What this does is when a player, Health hack or god hack it kicks them however is there approach to make it were if different players were godded turns there Health back to hundred and the Programmer godding himself get kick.
PS: Filtering Does not always work just saying
local MaxHealth = 120 game.Workspace.ChildAdded:connect(function(Child) local Humanoid = Child:FindFirstChild("Humanoid") local Player = game.Players:FindFirstChild(Child.Name) if Humanoid then Humanoid.Changed:connect(function() if Player and Humanoid.MaxHealth == math.huge then Player:Kick("You have lost connection to the game") elseif Player and Humanoid.MaxHealth > MaxHealth and Humanoid.MaxHealth < 9e9 then Player:Kick("You have lost connection to the game") elseif Player and Humanoid.MaxHealth == 0 and Humanoid.Health > 0 then Player:Kick("You have lost connection to the game") end end) end end)
Your question is very confusing, but I'll do my best to give an answer! =)
I'm assuming you're making an anti-hack where when the player's health goes to god, then it'll reset the player's health. Instead of checking for god, I feel it would be more efficient to check for anything over the max amount of health for your game.
local maxHealth = 120 -- Used to define the max amount of health for players. local player = game.Players.LocalPlayer --Can only be used in local scripts player.CharacterAdded:connect(char) --When the character is added local humanoid = char:WaitForChild('Humanoid') --Wait for Humanoid humanoid.HealthChanged:connect(function() --When the health is changed if humanoid.Health > maxHealth then --Is it higher than the max health? humanoid.Health = maxHealth --Change to max health end end) end)
This would be for a game that does not have FilteringEnabled
enabled. However if you do, you could run some remote events.
Local
local maxHealth = 120 -- Used to define the max amount of health for players. local player = game.Players.LocalPlayer --Can only be used in local scripts local event = game.ReplicatedStorage:WaitForChild('HealthChanged') --Requires RemoteEvent in Replicated Storage called HealthChanged player.CharacterAdded:connect(char) --When the character is added local humanoid = char:WaitForChild('Humanoid') --Wait for Humanoid humanoid.HealthChanged:connect(function() --When the humanoid's health changes if humanoid.Health > maxHealth then --Check for if it's higher than the maxHealth event:FireServer(humanoid) --Fire the server with the humanoid end end) end)
Server
local maxHealth = 120 -- Used to define the max amount of health for players. local event = game.ReplicatedStorage:WaitForChild('HealthChanged') --Grabs event event.OnServerEvent:connect(function(player, humanoid) --When the event is triggered by client, grab the player and humanoid humanoid.Health = maxHealth --Change the health to maxHealth end)
If the script is too confusing to read because of the comments I left, you can click the Script with Less than and Greater than arrows at the top right, whenever you hover over the script.
Now to talk about your script! =)
local MaxHealth = 120 game.Workspace.ChildAdded:connect(function(Child) --Bit strange to do. But I understand your usage of it. local Humanoid = Child:FindFirstChild("Humanoid") local Player = game.Players:FindFirstChild(Child.Name) if Humanoid then Humanoid.Changed:connect(function() --This will check for every single change in the humanoid, from if they're walking, to jumping, to falling, to anything. if Player and Humanoid.MaxHealth == math.huge then --I would do greater than your maxhealth, as some hackers will just change their health to right under god mode =) Player:Kick("You have lost connection to the game") elseif Player and Humanoid.MaxHealth > MaxHealth and Humanoid.MaxHealth < 9e9 then --Excess ElseIf Player:Kick("You have lost connection to the game") elseif Player and Humanoid.MaxHealth == 0 and Humanoid.Health > 0--Excess ElseIf then Player:Kick("You have lost connection to the game") end end) end end)
I hope you understand, and that the knowledge provided can help you in the future =).
PS: FilteringEnabled will catch a majority of hackers, unless they are highly experienced, and even then, anything you do they will bypass somehow.