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

My afk button does not return walkspeed to 32 when I turn it off. How do I fix this?

This is the code. The forcefield and walkspeed edit works when you first press it, but when you turn it off, it breaks, plus it keeps your walkspeed at 0 to top it all off.

This is the script:

local On = false

script.Parent.MouseButton1Down:connect(function()
	local player = script.Parent.Parent.Parent.Parent
	if On == false then
		On = true
		player.Character.Humanoid.WalkSpeed = 0
		force = Instance.new("ForceField",player.Character)
	elseif On == true then
		force:remove()
		player.Character.Humanoid.Walkspeed = 32
	end
end)

How do I fix my afk button? I want it to freeze the player's walkspeed and add a forcefield to the player, yet I want that to disable properly when I turn it off. I also want to fix the issue where it breaks after 1 use.

2 answers

✓ Accepted answer
local force
local on = false
script.Parent.MouseButton1Down:connect(function()
    local player = script.Parent.Parent.Parent.Parent

    on = not on

    if on then
        player.Character.Humanoid.WalkSpeed = 0
        force = Instance.new("ForceField",player.Character)
    else
        force:Destroy()
        player.Character.Humanoid.Walkspeed = 32
    end
end)

5 comments

0

This script does not seem to work at all.

0

Made a typo. Change the uppercase On to on.

0

While you did fix my issue with the not being able to reuse button, the player still doesn't return from 0 walkspeed. The character stays at 0 speed despite the clear command to set it to 32.

0

Another typo Walkspeed -> WalkSpeed

0

Great stuff!

local on = false
script.Parent.MouseButton1Click:Connect(function()
	if on == false then
		plr.Character.Humanoid.WalkSpeed = 0
local force = Instance.new("ForceField")
force.Parent = script.Parent.Parent.Parent.Parent.Character
		on = true
	else
					plr.Character.Humanoid.WalkSpeed = 32
script.Parent.Parent.Parent.Parent.Character.ForceField:Destroy()
on = false

	end
end)

Hopefully this works! Put it in a local script in your button.

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