Hello, I made a script where the players health can go infinite so players can’t kill the player while shopping. The Script does work, but I’m not sure how to make a close button go back to the players normal health. I am also using premium benefits so premium players normal health is 150, instead of the normal health 100.
Open Script:
local player = game:GetService("Players").LocalPlayer
local char = player.Character
script.Parent.MouseButton1Click:Connect(function()
local frame = script.Parent.Parent.MFrame
frame.Visible = true
script.Parent.Visible = false
char:WaitForChild("Humanoid").MaxHealth = math.huge
char:WaitForChild("Humanoid").Health = math.huge
end)
Just make a value that get’s the humanoids health.
Like, when it gets activated (MouseButton1Click), you should have a variable that gets the Players Max and Normal Health.
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local normHealth
local maxHealth
script.Parent.MouseButton1Click:Connect(function()
local frame = script.Parent.Parent.MFrame
frame.Visible = true
script.Parent.Visible = false
normHealth = char:WaitForChild("Humanoid").Health
maxHealth = char:WaitForChild("Humanoid").MaxHealth
wait()
char:WaitForChild("Humanoid").MaxHealth = math.huge
char:WaitForChild("Humanoid").Health = math.huge
end)
Now, if the two scripts are in the same script, you can just easily change the humanoid’s health to the now changed health values in the closed script.
Though, if it’s different scripts, you should make an int/number value to be created once clicked. Then change the value of that instance into the initual normal/max health, so that the close script can get that information then delete it.
So, like this:
Open Script
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local normHealth = Instance.new("IntValue")
local maxHealth = Instance.new("IntValue")
normalHealth.Name = "NormalHealth"
normalHealth.Parent = script.Parent
maxHealth.Name = "MaxHealth"
maxHealth.Parent = script.Parent
script.Parent.MouseButton1Click:Connect(function()
local frame = script.Parent.Parent.MFrame
frame.Visible = true
script.Parent.Visible = false
normHealth.Value = char:WaitForChild("Humanoid").Health
maxHealth.Value = char:WaitForChild("Humanoid").MaxHealth
wait()
char:WaitForChild("Humanoid").MaxHealth = math.huge
char:WaitForChild("Humanoid").Health = math.huge
end)
Close Script
local Player = game.Players.LocalPlayer
local Humanoid = Player.Character:WaitForChild("Humanoid")
local normHealth = script.Parent:WaitForChild("NormalHealth")
local maxHealth = script.Parent:WaitForChild("MaxHealth")
script.Parent.MouseButton1Click:Connect(function()
if normHealth and maxHealth then
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Shop.Visible = true
Humanoid.Health = normHealth.Value
Humanoid.MaxHealth = maxHealth.Value
end
end)
Hope this helps! If there’s anything else you need help for, you can either make another post or PM me! Good luck on your game <3