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

Help me fix my speed boost (simple script)?

Asked by 3 years ago

I need help with this script for a food in my game. The idea of the script is that it gives the player a speed boost for a few moments and then it finishes but it doesn't seem to do that for my script:

local Tool = script.Parent;

Enabled = true

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        if not Enabled  then
            return
        end
        Enabled = false
        local h = Tool.Parent:FindFirstChild("Humanoid")
        h.WalkSpeed = 50
        wait(1)
        h.walkSpeed = 16
    end)
end)

script.Parent.Unequipped:Connect(function()
end)

Than you.

0
Have you tried using a local function instead of anonymous functions? misha123 83 — 3y

3 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

There are some small mistakes. The first one is that .Equipped returns the tool as an argument, not the mouse. Another one is that on the second "WalkSpeed" you wrote "walkSpeed". And I also overall optimized it.

local player = game.Players.LocalPlayer

local tool = script.Parent

local mouse = player:GetMouse()

local enabled = false

tool.Equipped:Connect(function(tool)

    mouse.Button1Down:Connect(function()

        if enabled then return end

        enabled = true
        local humanoid = player.Character.Humanoid
        humanoid.WalkSpeed = 50
        wait(1)
        humanoid.WalkSpeed = 16
        enabled = false

    end)

end)
0
I didn't work. if it's longer than two seconds it doesn't work Elimonater10000 33 — 3y
0
What do you mean? I saw you have an animation, maybe the animation is only 2 seconds and after that it breaks it? User#32819 0 — 3y
0
I'll have a look Elimonater10000 33 — 3y
0
I think it's because it destroys the tool but I'm having trouble rearranging the script Elimonater10000 33 — 3y
View all comments (18 more)
0
Do you have discord or something like that it'll be easier to fix it User#32819 0 — 3y
0
I found out my problem, it was on the gui, the script.Parent.remove. But I'm still having trouble that when the play drops the item (by pressing backspace) the effect doesn't wear off. Elimonater10000 33 — 3y
0
Use :Destroy() instead of :remove() as it's deprecated User#32819 0 — 3y
0
in which script and where? Elimonater10000 33 — 3y
0
didn't work Elimonater10000 33 — 3y
0
I don't know, the script you have posted are old so I don't know how they currently look like User#32819 0 — 3y
0
U got any other ideas? Elimonater10000 33 — 3y
0
Well, the one in this answer should work perfectly, if it doesn't work then there are other scripts interfering with the tool User#32819 0 — 3y
0
ok Elimonater10000 33 — 3y
0
It still doen't work. Do you know a script that changes the WalkSpeed to 16 when it's dropped? Elimonater10000 33 — 3y
0
Yeah, I can write one, but I have to get off the pc in about 10 minutes User#32819 0 — 3y
0
ok Elimonater10000 33 — 3y
0
It doesn't have to be today if you can't do it. I can be whenever you are able to Elimonater10000 33 — 3y
0
Alright, do you have discord because communicating via comments is slow User#32819 0 — 3y
0
I do Elimonater10000 33 — 3y
0
pixie6500#7494 is my name on it Elimonater10000 33 — 3y
0
I gtg now, send me friend request if u can, bye Elimonater10000 33 — 3y
0
ur sneaker peaker, right? Elimonater10000 33 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

Well, that didn't work I'll show you my scripts:

WELDING:

local Tool = script.Parent;

Enabled = true

function onActivated()
    if not Enabled  then
        return
    end
    Enabled = false
    wait(1)
    script.Parent.Handle.EatingSound:Play()
    wait(2)
    local h = Tool.Parent:FindFirstChild("Humanoid")
    if (h ~= nil) then
        if (h.MaxHealth > h.Health + 10) then
            h.Health = h.Health + 10
        else    
            h.Health = h.MaxHealth
        end
    end
    wait(1)
    script.Parent:remove()
end

function onEquipped()
    script.Parent.Handle.OpenSound:play()
    script.Parent:remove()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

SPEED BOOST:

local Tool = script.Parent
local db = false

script.Parent.Activated:Connect(function()
    local h = Tool.Parent:FindFirstChild("Humanoid")
    if db == false then -- Debounce statement so you can't eat the food while still under its effects
        db = true
        h.WalkSpeed = 50
        wait(10)
        h.WalkSpeed = 16
        db = false
    end
end)

GUI:

Enabled = true

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        if not Enabled then
            return
        end
        Enabled = false
        animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
        animation:Play()
        wait(5)
        script.Parent:Destroy()
    end)
end)
script.Parent.Unequipped:Connect(function()
    animation:Stop()
end)
Log in to vote
0
Answered by 3 years ago

There's a .Activated event for a tool that fires when the mouse is clicked while the tool is equipped. It's much less convoluted and more effective than what you were doing before.

local Tool = script.Parent
local db = false

script.Parent.Activated:Connect(function()
    local h = Tool.Parent:FindFirstChild("Humanoid")
    if db == false then -- Debounce statement so you can't eat the food while still under its effects
        db = true
        h.WalkSpeed = 50
        wait(1)
        h.WalkSpeed = 16
        db = false
    end
end)

0
Actually no. I still use Button1Down, because Activated does not work when you hold control so it limits possibilities. XxWingKing 96 — 3y
0
It's still not working. It only works when my timer is 1 or 2. I think it's to do with the script.Parent.Remove(). Have you got any ideas? Elimonater10000 33 — 3y

Answer this question