I was thinking about the OnServerEvent function, I don’t know if it’s a function or whatever but, it does work. Thank you. Do I put a else statement to make a ungod button with the same button?
I also more likely get what remote event is used for. Might use it in the future. Thanks to your script that I learned how to use the remote event.
You’ll need a suitable condition to set the players health back to 100.
local replStorage = game:GetService("ReplicatedStorage")
local healthRemote = replStorage:WaitForChild("HealthRemote")
healthRemote.OnServerEvent:Connect(function(player, humanoid)
if humanoid.MaxHealth <= 100 then
humanoid.MaxHealth = 99999
humanoid.Health = 99999
else
humanoid.Health = 100
humanoid.MaxHealth = 100
end
end)
Server script, this will essentially turn the button into a godmode toggle button. On the first click they will be given godmode, on the second the godmode will be removed. I’m not sure how you intend for this button to work in the future.
If you want it to UnGod you can do:
local Button = script.Parent
local Event = game.ReplicatedStorage.RemoteEvent -- Replace with your remote event name
local God = false
Button.MouseButton1Click:Connect(function()
if god == false then
Event:FireServer("Enable")
god = true
else
Event:FireServer("Disable")
god = false
end
end)
local Event = game.ReplicatedStorage.RemoteEvent -- Replace with your remote event name
Event.OnServerEvent:Connect(function(player, status)
if status == "Enable" then
local char = player.Character or player.CharacterAdded:Wait()
char.Humanoid.MaxHealth = math.huge()
char.Humanoid.Health = math.huge()
else
local char = player.Character or player.CharacterAdded:Wait()
char.Humanoid.MaxHealth = 100
char.Humanoid.Health = 100
end
end)
I actually putted a “h = true” instead, but thanks though.
local h = true
local Event = game.ReplicatedStorage.RemoteEvent
Event.OnServerEvent:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
if h == true then
h = false
char.Humanoid.Health = math.huge
char.Humanoid.MaxHealth = math.huge
else
h = true
char.Humanoid.Health = 100
char.Humanoid.MaxHealth = 100
end
end)
I just noticed this won’t work since you’re attempting to call “math.huge” which is a number value.
I don’t understand? What do you mean? math.huge()
just returns a large numerical value.
I see you’ve corrected math.huge() to math.huge, congrats. You could also turn the variable “h” into a debounce by adding “task.wait()” commands & return statements in the appropriate locations.
That’ll prevent the godmode button from being abused.
Alright, I don’t really know why people uses debounce, and what its purpose is. So I’d just change it to some random variable.
Test print(math.huge())
in a script, you’ll get a “attempt to call a number value” error. Since math.huge is a constant not a function.
The primary purpose of a debounce is to prevent a function from being executed too many times.
Oh, alright. I’ll add it. Thanks.
Ah, I see. I didn’t realise that, apologies.