Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Return Players Health back to 100 when god?

Asked by 7 years ago
Edited 7 years ago

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)


0
FilteringEnabled will catch a majority of hackers, unless they are highly experienced, and even then, anything you do they will bypass somehow. Async_io 908 — 7y
0
*script kiddies *exploiters smh Programical 653 — 7y

1 answer

Log in to vote
0
Answered by
Async_io 908 Moderation Voter
7 years ago

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.

0
Imo, it's repetitive to compare a value to math.huge; I believe using the '>' operator is enough. TheeDeathCaster 2368 — 7y
0
That's what I said. Async_io 908 — 7y
Ad

Answer this question