God GUI not working

I was making a God GUI for a agency game for a certain team, but my script just doesn’t work at all.

function click()
	game.Players.PlayerAdded:Connect(function(plr)
		plr.CharacterAdded:Connect(function(char)
			local h = char:FindFirstChild("Humanoid")
			if h then
				h.MaxHealth = math.huge
				h.Health = math.huge
			else
				h.MaxHealth = 100
				h.Health = 100
			end
		end)
	end)
end
script.Parent.MouseButton1Click:Connect(click)


I’m not sure what is wrong with it, there’s no error in the output.

local players = game:GetService("Players")
players.PlayerAdded:wait()
local player = players.LocalPlayer
player.CharacterAdded:wait()
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

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

script.Parent.MouseButton1Click:Connect(click)

This will need to be inside a local script parented to the button which is clicked.

Put a remote event in rep storage

Server script in server script service:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remote = ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(activator)
	for _,v in pairs(workspace:GetDescendants()) do
		if v:IsA("Humanoid") then
			local player = Players:GetPlayerFromCharacter(v.Parent)
			coroutine.wrap(function() -- without this the whole script would yield until the watched values are nil
				while player and player.Character.Humanoid and player.Team == activator.Team do
					player.Character.Humanoid.Health = 9999999
					wait(3)
				end
			end)
		end
	end
end)

Local script in the button

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

I’m pretty sure that should be avoided.

@tcxtic_al , there is no need to listen for a new player to join, nor his character being loaded, as the client can already access its local player object at Players.LocalPlayer. And using FindFirstChild to obtain the Humanoid will either return nil or the object, meaning you can just attempt to perform changes to the Humanoid if it doesn’t exist.

They can, I do it all the time. I updated it just incase I’m remembering incorrectly.

This would only replicate to the client.

Nevermind. Not sure what to do. Probably shouldn’t be giving the client this power anyways…

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.