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
local player = game.Players.LocalPlayer
player.CharacterAdded:connect(char)
local humanoid = char:WaitForChild('Humanoid')
humanoid.HealthChanged:connect(function()
if humanoid.Health > maxHealth then
humanoid.Health = maxHealth
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
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage:WaitForChild('HealthChanged')
player.CharacterAdded:connect(char)
local humanoid = char:WaitForChild('Humanoid')
humanoid.HealthChanged:connect(function()
if humanoid.Health > maxHealth then
event:FireServer(humanoid)
end
end)
end)
Server
local maxHealth = 120
local event = game.ReplicatedStorage:WaitForChild('HealthChanged')
event.OnServerEvent:connect(function(player, humanoid)
humanoid.Health = 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)
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)
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.
2 comments
FilteringEnabled will catch a majority of hackers, unless they are highly experienced, and even then, anything you do they will bypass somehow.
*script kiddies *exploiters smh