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

How do I fix my AFK script, so that when people turn it on, they can't be hurt?

Despite adding a forcefield, you are still able to lose health, apparently.

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)

1 answer

Try saving the amount of health they have when they turn on AFK. Then, when the health changes/repeatedly change their health to the amount that was saved. You will probably want to attach a value to a player/character and store the health in there so that you can change the health later on (also, you might want to put it outside of the connect and use a loop to check if on is true and then change the health.

2 comments

0

dumb it down for me i am scripting boomer

0

Set a variable with the player's health in it, and as long as they are AFK their health should always be set to that variable.

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