God GUI not working

I used else to disable the god mode. Both of them don’t work.

Doesn’t work. I have put the server script in the serverscriptservice, and the local script in the gui button.

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

function click()
	humanoid.MaxHealth = 999999
	humanoid.Health = 999999
end

script.Parent.MouseButton1Click:Connect(click)

image

This is working for me. Make sure everything is organised like in the above.

Client Code:

@tcxtic_al

local Button = script.Parent
local Event = game.ReplicatedStorage.RemoteEvent -- Replace with your  remote event name

Button.MouseButton1Click:Connect(function()
    Event:FireServer()
end)

Server Code:

local Event = game.ReplicatedStorage.RemoteEvent -- Replace with your  remote event name

Event.OnServerEvent:Connect(function(player)
    local char = player.Character or player.CharacterAdded:Wait()

    char.Humanoid.MaxHealth = math.huge()
    char.Humanoid.Health = math.huge()
end)

Also the code in the body of the else expression would never be executed since only a player can trigger a GuiObject.MouseButton1Click event.

1 Like

Yeah I did put the local script in the textbutton.

1 Like

This won’t work as you’re changing the health on the client. So it would only change the health for that player.

Copy and paste the code into the local script that I provided in the same reply.

1 Like

I thought this was a solo game, one moment.

– LOCAL SCRIPT –

local replStorage = game:GetService("ReplicatedStorage")
local healthRemote = replStorage:WaitForChild("HealthRemote")

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

function click()
	healthRemote:FireServer(humanoid)
end

script.Parent.MouseButton1Click:Connect(click)

–SERVER SCRIPT–

local replStorage = game:GetService("ReplicatedStorage")
local healthRemote = replStorage:WaitForChild("HealthRemote")

healthRemote.OnServerEvent:Connect(function(player, humanoid)
	humanoid.MaxHealth = 99999
	humanoid.Health = 99999
end)

image

How everything is organised.

When using FireServer(), you don’t have to pass in the player argument, as you’re firing it from the client. OnServerEvent automatically gets the player parameter.

Event:FireServer()

Event.OnServerEvent:Connect(function(player)

end)

Made the edit before you replied.

Oops apologies. Didn’t see it there.

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.

1 Like
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.