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

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

Asked by
Mycran 7
5 years ago

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:

01local On = false
02 
03script.Parent.MouseButton1Down:connect(function()
04    local player = script.Parent.Parent.Parent.Parent
05    if On == false then
06        On = true
07        player.Character.Humanoid.WalkSpeed = 0
08        force = Instance.new("ForceField",player.Character)
09    elseif On == true then
10        force:remove()
11        player.Character.Humanoid.Walkspeed = 32
12    end
13end)

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01local force
02local on = false
03script.Parent.MouseButton1Down:connect(function()
04    local player = script.Parent.Parent.Parent.Parent
05 
06    on = not on
07 
08    if on then
09        player.Character.Humanoid.WalkSpeed = 0
10        force = Instance.new("ForceField",player.Character)
11    else
12        force:Destroy()
13        player.Character.Humanoid.Walkspeed = 32
14    end
15end)
0
This script does not seem to work at all. Mycran 7 — 5y
0
Made a typo. Change the uppercase On to on. EncapsuIation 450 — 5y
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. Mycran 7 — 5y
0
Another typo Walkspeed -> WalkSpeed EncapsuIation 450 — 5y
0
Great stuff! Mycran 7 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01local on = false
02script.Parent.MouseButton1Click:Connect(function()
03    if on == false then
04        plr.Character.Humanoid.WalkSpeed = 0
05local force = Instance.new("ForceField")
06force.Parent = script.Parent.Parent.Parent.Parent.Character
07        on = true
08    else
09                    plr.Character.Humanoid.WalkSpeed = 32
10script.Parent.Parent.Parent.Parent.Character.ForceField:Destroy()
11on = false
12 
13    end
14end)

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

Answer this question