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)
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