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:
01 | local On = false |
02 |
03 | script.Parent.MouseButton 1 Down: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 |
13 | 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.
01 | local force |
02 | local on = false |
03 | script.Parent.MouseButton 1 Down: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 |
15 | end ) |
01 | local on = false |
02 | script.Parent.MouseButton 1 Click:Connect( function () |
03 | if on = = false then |
04 | plr.Character.Humanoid.WalkSpeed = 0 |
05 | local force = Instance.new( "ForceField" ) |
06 | force.Parent = script.Parent.Parent.Parent.Parent.Character |
07 | on = true |
08 | else |
09 | plr.Character.Humanoid.WalkSpeed = 32 |
10 | script.Parent.Parent.Parent.Parent.Character.ForceField:Destroy() |
11 | on = false |
12 |
13 | end |
14 | end ) |
Hopefully this works! Put it in a local script in your button.