God doesn't set my hp to math.huge, no errors

I was making a god command for a friend’s scp game but whenever I test it, it’s just doesn’t change my health to math.huge or infinite if you prefer.

local config = require(game:GetService("ServerScriptService").ParalaxAdmin.Setup)
local godData = game:GetService("DataStoreService"):GetDataStore("god81SSQQFIJQDQVJDIOF")

local function GetPlayer(String)
	for i,v in pairs(game.Players:GetPlayers()) do
		if (string.sub(string.lower(v.Name), 1, string.len(String))) == string.lower(String) then
			return v
		end
	end
end
local target
game.Players.PlayerAdded:Connect(function(plr)
	wait(game:IsLoaded())
	if plr:GetRankInGroup(config.GroupID) >= 4 then
		plr.Chatted:Connect(function(msg)
			local args = msg:split(" ")
			if args[1] == ":god" then
				if args[2] then
					if args[2] == "me" then
						target = plr
					elseif args[2] == "admins" then
						for i,v in pairs(game.Players:GetPlayers()) do
							if v:GetRankInGroup(config.GroupID) >= 4 then
								target = v
							else
								target = GetPlayer(args[2])
							end
							if args[3] then
								if args[3] == true then
									godData:SetAsync(target.UserId,true)
								end
								local humanoid = target.Character:FindFirstChild("Humanoid")
								humanoid.MaxHealth = math.huge
								humanoid.Health = math.huge
							end
						end
						local humanoid = target.Character:FindFirstChild("Humanoid")
						humanoid.Died:Connect(function(char)
							if godData:GetAsync(target.UserId,true) then
								humanoid.MaxHealth = math.huge
								humanoid.Health = math.huge
							end
						end)
					end
				end
			end
		end)
	end
end)
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		local InfHealth = math.huge
		Humanoid.MaxHealth = InfHealth
		Humanoid.Health = InfHealth
	end)
end)

this works for me, I think you have to add the CharacterAdded function. I tried the same thing only with PlayerAdded and defining the Humanoid with Player.Character:WaitForChild(“Humanoid”). This got printed out as nil

1 Like

You could try something like so:


local Players = game:GetService("Players")

local function SetGodHealth(Player)
	-- Authorization check(s) here

	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		
		Humanoid.MaxHealth = math.huge --/ If this doesn't work, you could also set it to a high number and whenever the humanoid takes damage, just reset the health. The same goes for the below.
		Humanoid.Health = math.huge
	end)
end

Players.PlayerAdded:Connect(SetGodHealth)

Also, how are you damaging the player? If you’re just setting the health in workspace, this script won’t work since it’s a one-time thing.

1 Like

This didn’t work. I added the function and used it but I still had no hp changed.

Try debugging your code, add prints to see how far the code goes. If you aren‘t high ranked in your group it could be a reason too. And maybe look for errors in output :slight_smile:

Any errors in output? If so let me know.