Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help me fix my speed boost (simple script)?

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.

1 comment

0

Have you tried using a local function instead of anonymous functions?

3 answers

✓ Accepted answer

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)

22 comments

0

I didn't work. if it's longer than two seconds it doesn't work

0

What do you mean? I saw you have an animation, maybe the animation is only 2 seconds and after that it breaks it?

0

I'll have a look

0

I think it's because it destroys the tool but I'm having trouble rearranging the script

0

Do you have discord or something like that it'll be easier to fix it

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.

0

Use :Destroy() instead of :remove() as it's deprecated

0

in which script and where?

0

didn't work

0

I don't know, the script you have posted are old so I don't know how they currently look like

0

U got any other ideas?

0

Well, the one in this answer should work perfectly, if it doesn't work then there are other scripts interfering with the tool

0

ok

0

It still doen't work. Do you know a script that changes the WalkSpeed to 16 when it's dropped?

0

Yeah, I can write one, but I have to get off the pc in about 10 minutes

0

ok

0

It doesn't have to be today if you can't do it. I can be whenever you are able to

0

Alright, do you have discord because communicating via comments is slow

0

I do

0

pixie6500#7494 is my name on it

0

I gtg now, send me friend request if u can, bye

0

ur sneaker peaker, right?

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)

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)

2 comments

0

Actually no. I still use Button1Down, because Activated does not work when you hold control so it limits possibilities.

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.