Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to add a tool debounce, only removes the tools you have equip (?)

Asked by 2 years ago

Ello Developers!

Okay, yes, the title may look nonsense, but bear with me, Ill give context, basically, the script below this text Is where when the script Is enabled (It Is enabled by another script thats clones the script below and enables It) the users current Items will be parented In a folder In ReplicatedStorage and will jump very high, after a few seconds, the user will have back there Items and there original Speed and JumpPower, the problem however Is doing to be the first 6 lines after the "if script.Enabled == true then". It will only "remove" and bring back the tools you currently equip, not very tool you have. Now you may be wondering why I was trying to make It so that It will parent your current tools to a folder In ReplicatedStorage and after a few seconds, It will parent It back to you, well I want that I wanted to do make sure that anything that effects the player doesn't break, basically, If your using a tool that Is currently doing "tool.Parent.Humanoid.WalkSpeed" stuff (Like changing speed for Instance) and unequip It, the code will break and you will stay at the constant speed you are In until you use It again, If that even makes sense...

Script:

local NPC = script.Parent

if script.Enabled == true then
    local NPCWeaponsCheck = NPC:GetChildren()
    for _, Weapons in ipairs(NPCWeaponsCheck) do
        if Weapons:IsA("Tool") then
            Weapons.Parent = game:GetService("ReplicatedStorage").StorageForMoves
        end
    end
    local POW = NPC.Humanoid:WaitForChild("Animator"):LoadAnimation(NPC.Smash)
    POW:Play()
    local OriginalSpeed = Instance.new("NumberValue",NPC)
    game:GetService("Debris"):AddItem(OriginalSpeed,5)
    local OriginalJumpPower = Instance.new("NumberValue",NPC)
    game:GetService("Debris"):AddItem(OriginalJumpPower,5)
    OriginalSpeed.Value = NPC.Humanoid.WalkSpeed
    OriginalJumpPower.Value = NPC.Humanoid.JumpPower
    NPC.Humanoid.WalkSpeed = 0
    NPC.Humanoid.JumpPower = 120
    wait(0.20)
    local CanDamage = true
    script.SmashGround:Play()
    script.Flying:Play()
    NPC.Humanoid.Jump = true
    NPC.Humanoid.WalkSpeed = 50
    local Pound = game:GetService("ReplicatedStorage").Smash:Clone()
    game:GetService("Debris"):AddItem(Pound,5)
    Pound.Parent = game.Workspace
    Pound.Position = NPC.Torso.Position
    Pound.Position = Pound.Position + Vector3.new(0,-1,0)
    Pound.Size = Vector3.new(1,1,1)
    Pound.BrickColor = BrickColor.White()
    Pound.Material = Enum.Material.Plastic
    local TweenProperty = {
        Size = Pound.Size + Vector3.new(25,0.3,25),
        Transparency = 1
    }
    local Tweeninfo = TweenInfo.new(
        1,
        Enum.EasingStyle.Circular,
        Enum.EasingDirection.InOut,
        0,
        false,
        0
    )
    local Tween = game:GetService("TweenService"):Create(Pound,Tweeninfo,TweenProperty)
    Tween:Play()
    Pound.Touched:Connect(function(hit)
        local humanoid = hit.Parent:WaitForChild("Humanoid")
        if humanoid ~= NPC.Humanoid and CanDamage == true then
            humanoid:TakeDamage(30)
            CanDamage = false
            wait(.05)
            CanDamage = true
        end
    end)
    wait(1)
    game:GetService("Debris"):AddItem(Pound,0)
    NPC.Humanoid.WalkSpeed = OriginalSpeed.Value
    NPC.Humanoid.JumpPower = OriginalJumpPower.Value
    game:GetService("Debris"):AddItem(OriginalSpeed,0)
    game:GetService("Debris"):AddItem(OriginalJumpPower,0)
    for _, Weapons2 in ipairs(NPCWeaponsCheck) do
        if Weapons2:IsA("Tool") then
            Weapons2.Parent = NPC
        end
    end
end

Answer this question