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.
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)
@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.
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)
This is working for me. Make sure everything is organised like in the above.
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)
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)
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.