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
4 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:

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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)
0
This script does not seem to work at all. Mycran 7 — 4y
0
Made a typo. Change the uppercase On to on. EncapsuIation 450 — 4y
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 — 4y
0
Another typo Walkspeed -> WalkSpeed EncapsuIation 450 — 4y
0
Great stuff! Mycran 7 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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.

Answer this question