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

How can I fix this script where if the player equips the tool, their speed will change?

Asked by 4 years ago

So uhmmm the title speaks for itself. What am I doing wrong?

Tool = script.Parent


Humanoid.WalkSpeed = (16 * 2) --- changes the player speed or velocity
    Sounds.Unsheath:Play()
    ToolEquipped = true
end

function Unequipped()
    if CheckIfAlive() then
        Humanoid.WalkSpeed = 16
    end
    ToolEquipped = false
end

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Tool.Equipped will listen for when said tool is equipped. Tool.Unequipped will do the same for unequipped. And you'd also need to specify the humanoid as well. Here's a very basic sample script:

Tool.Equipped:Connect(function() --Will listen for when the player equips the tool then connects to the enclosed function
    local char = Tool.Parent --When a tool is equipped it moves from the backpack to the character model
    char.Humanoid.WalkSpeed = 32 --Sets the walkspeed by finding the humanoid that's under the character
end)

Scripts are not inherently smart and thus, you will need to feed them all the information that they actually need and tell them when and what to listen for.

0
There's an error: 21:17:25.589 - Players.Simpletton.Backpack.Shotgun.Scripts.Speed:4: ')' expected (to close '(' at line 1) near '<eof>' Simpletton 82 — 4y
0
Ahh, nevermind I just had to set the tool's variable to your script, thanks for your help Simpletton 82 — 4y
0
Oh whoops. Minor parenthesis mistake XxTrueDemonxX 362 — 4y
Ad

Answer this question