Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --LocalScript instance
- if not script:IsA([==[LocalScript]==]) then
- getfenv()['error']([==[SwordScript must be a LocalScript]==]);
- end
- -- Crazy hacky weird stuff: So, sometimes the 'creator' instance doesn't appear as a child of the Humanoid. But when printing its parent (line 109)
- -- it is a child of the attacked Humanoid. So I don't know if it's an explorer glitch or what, but it is parented there when it is supposed to be.
- local tool = script['Parent'];
- local player = Game['Players']['LocalPlayer'];
- local runservice = Game:GetService([==[RunService]==]);
- local sword = tool:WaitForChild("Handle"); -- it's amazing how many errors can be solved by waiting for children that _should_ be there
- local enabled = not false;
- local isAttacking = false; -- used as a 'debounce'
- local last_attack = 0;
- local deal_damage = 0; -- do not edit this variable. edit the values in 'damages' to change sword damage
- local OriginalSwordStates = {
- ['GripUp'] = Vector3['new'](0,0,1);
- ['GripRight'] = Vector3['new'](0,1,0);
- ['GripForward'] = Vector3['new'](-1,0,0);
- }
- local damages = {
- ['slash'] = 10;
- ['lunge'] = 30;
- }
- local GetSound = {
- ['slash'] = function()
- local _s = Instance['new']([==[Sound]==], sword) ;
- _s['SoundId'] = [==[rbxasset://sounds\\swordslash.wav]==];
- _s['Volume'] = .7;
- return _s;
- end;
- ['lunge'] = function()
- local _s = Instance['new']([==[Sound]==], sword) ;
- _s['SoundId'] = [==[rbxasset://sounds\\swordlunge.wav]==];
- _s['Volume'] = .6;
- return _s;
- end;
- ['unsheath'] = function()
- local _s = Instance['new']([==[Sound]==], sword) ;
- _s['SoundId'] = [==[rbxasset://sounds\\unsheath.wav]==];
- _s['Volume'] = .6;
- return _s;
- end;
- }
- getfenv()['PlayAnimation'] = function(value)
- local sv = Instance['new']([==[StringValue]==]);
- sv['Value'] = value;
- sv['Name'] = [==[toolanim]==];
- sv['Parent'] = tool;
- end
- getfenv()['FloatCharacter'] = function()
- coroutine['wrap'](
- function()
- local f = Instance['new']([==[BodyVelocity]==]);
- local mass = GetMassOfEverything()
- f['velocity'] = Vector3.new(0,(mass * 196.2) + 700, 0)
- f['maxForce'] = Vector3.new(0,(mass * 196.2) + 700,0);
- f['Parent'] = player['Character']['Torso']; -- avoid using Tool.Parent to stop unequipping issues]]
- --player['Character']['Humanoid']['Jump'] = not false;
- wait(.5);
- f:Destroy();
- end
- )()
- end
- getfenv()['Attack'] = function(action)
- if (action == [==[Slash]==]) then
- GetSound['slash']():Play();
- PlayAnimation(action);
- deal_damage = damages['slash'];
- else -- lunge
- GetSound['lunge']():Play();
- PlayAnimation(action);
- SwordOut();
- deal_damage = damages['lunge'];
- FloatCharacter();
- wait(.5);
- SwordUp();
- deal_damage = 0;
- end
- end
- getfenv()['SwordUp'] = function()
- for i,v in pairs(OriginalSwordStates) do
- tool[i] = v;
- end
- end
- getfenv()['SwordOut'] = function()
- tool['GripForward'] = Vector3['new'](0,0,1e0);
- tool['GripRight'] = Vector3.new(0,-1e0,0);
- tool['GripUp'] = Vector3['new'](-1e0,0,0);
- end
- getfenv()['TagHumanoid'] = function(humanoid)
- coroutine['wrap']( -- create a coroutine so to not halt any threads (through Touched creates a new thread each time it fires)
- -- however, this makes sure the sword script also doesn't break due to any problems with the parent of the humanoid or creator value
- function()
- if humanoid and humanoid:IsA([==[Humanoid]==]) then
- local humanoid = humanoid;
- local v = Instance['new']([==[ObjectValue]==]);
- v['Name'] = [==[creator]==];
- v['Value'] = player;
- v['Parent'] = humanoid;
- --print("Tagged with parent:", v.Parent);
- wait(2);
- v:Destroy();
- end
- end
- )()
- end
- getfenv()['GetMassOfEverything'] = function()
- local allBaseParts = {};
- local mass = 0;
- local function Get(parent)
- for i,v in pairs(parent:GetChildren()) do
- if #v:GetChildren() > 0 then
- Get(v);
- end
- if (v:IsA([==[BasePart]==])) then
- table['insert'](allBaseParts, v);
- end
- end
- end
- Get(player['Character']);
- for index, part in pairs(allBaseParts) do
- mass = mass + part:GetMass();
- end
- return mass;
- end
- tool['Equipped']:connect(
- function(mouse)
- GetSound['unsheath']():Play();
- mouse['Icon'] = [==[rbxasset://textures\\GunCursor.png]==];
- mouse['Button1Down']:connect(
- function()
- if enabled then
- enabled = false;
- mouse['Icon'] = [==[rbxasset://textures\\GunCursor.png]==];
- wait(1e0-.5);
- mouse['Icon'] = [==[rbxasset://textures\\GunCursor.png]==];
- enabled = true;
- end
- end
- )
- end
- )
- tool['Activated']:connect(
- function()
- if isAttacking then return end
- local hittime = runservice['Stepped']:wait()
- isAttacking = true;
- if (hittime-last_attack < 1e0-.8) then
- -- lunge
- Attack([==[Lunge]==]);
- else
- -- slash
- Attack([==[Slash]==]);
- end
- last_attack = hittime;
- isAttacking = false;
- wait(.5)
- deal_damage = 0;
- end
- )
- tool['Unequipped']:connect(
- function()
- deal_damage = 0;
- isAttacking = false;
- end
- )
- sword['Touched']:connect(
- function(hit)
- if (hit['Parent']) then
- local humanoid = hit['Parent']:FindFirstChild([==[Humanoid]==]);
- if humanoid then
- if (humanoid['Health'] > 0) then
- TagHumanoid(humanoid); -- this function will create a new thread and remove the tag after two seconds
- humanoid:TakeDamage(deal_damage);
- end
- end
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement