player = script.Parent.Parent.Parent.Parent.Character
playerinplayers = script.Parent.Parent.Parent.Parent
function AFK()
player.Humanoid.MaxHealth = 10000000000
player.Humanoid.Health = 10000000000
player.Humanoid.WalkSpeed = 0
playerinplayers.Backpack.Clean:Destroy()
script.Parent.Visible = false
script.Parent.Parent.AFKOff.Visible = true
end
script.Parent.MouseButton1Click:connect(AFK)
✓ ANSWER ACCEPTED
This doesn't work outside of studio/ It doesn't work in game, help me out?
1 answer
✓ Accepted answer
If your using filtering enabled, use a local script when having scripts in a gui. Second, some of the values your changing will only apear on the client, and not on the server. To get it to work properly, use a remote event. The following script will work with a remote event named "Afk" in ReplicatedStorage.
LocalScript inside the button:
local event = game:GetService('ReplicatedStorage'):WaitForChild('Afk')--get the event in ReplicatedStorage named Afk
local player = game.Players.LocalPlayer--get the player
function AFK()
event:FireServer(player.Character)--give the server the player's character
if player.Character then--check if character spawned in
script.Parent.Visible = false
script.Parent.Parent.AFKOff.Visible = true
end
end
script.Parent.MouseButton1Click:connect(AFK)
Script inside ServerScriptService:
local event = game:GetService('ReplicatedStorage'):WaitForChild('Afk')--get the event in ReplicatedStorage named Afk
event.OnServerEvent:Connect(function(plr,character)--receive information from client
if character then--make sure character is spawned in
local hum = character:FindFirstChild("Humanoid")
if hum then
hum.MaxHealth = 1000000000--give the huge amount of helath
hum.Health = 1000000000--same as above
hum.WalkSpeed = 0--unable to move
hum.JumpPower = 0--unable to jump
local back = player:WaitForChild("Backpack")
back:ClearAllChildren()--clear their backpack
end
end
end
Hope I could help, if you have any questions comment them below, and have a great day.
-REALTimothy0812
2 comments
0
thank you so much!
0
There is another script I'm having trouble with, how would I remove a model from the workspace for only that player?
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
Please note that I have FilteringEnabled on
Okay, a few questions. What outcome do you want? Are there any errors in the output? If there are, what are they? Also where is this script, inside a Gui or somewhere else?
And is it a script or local script?
it's not a localscript, inside a gui, i hooked up the parents because i know using game.Players.LocalPlayer.Characet won't work, so i figured that out, the outcome i want is to be an AFK button, in the game your character is always exposed to getting killed/damaged, and when people go afk i want them to be free from that, so the point of this is to take their clean tool away [sword basically]
and restrict their movment [their walkspeed 0]