Help with God Mode Command

I am making a god mode command for my game and im kinda stuck. The problem is, can ungod myself. Can someone help me!

players.PlayerAdded:Connect(function(player)		
	if player:GetRankInGroup(Settings.Main.RoCore) >= Settings.Main.RequiredRank or Settings.Main.VipOwners == player.UserId or player.Name == "Player2" then
		
		player.Chatted:Connect(function(message)
			message = string.lower(message)
			local splitMessage = string.split(message, " ")
			
			
			local humanoid = player.Character:WaitForChild("Humanoid")
			
			
			if splitMessage[1] == Settings.Fun.God then
				HealthBool = true
				humanoid.HealthChanged:Connect(function()
					humanoid.Health = 100
				end)
			elseif splitMessage[1] == Settings.Fun.Ungod then
				if HealthBool == true then
					HealthBool = false
					humanoid.Health = 99
				end
			end
		end)
	end
end)

ignore the settings.Fun or the Settings Module is just there as a settings for the admin command!

can anyone help me with this, i really need this to get working!

You can or can’t ungod yourself?

humanoid.HealthChanged:Connect(function()
	humanoid.Health = 100
end)

This function needs to be disconnected when the player requests to ungod themselves otherwise their health will just revert back to 100 when they are damaged.

it didnt work

Summary

This text will be hidden

Apologies, I didn’t mean to send a copy of your code. You need to fix the issue I mentioned above.

so i haved to use healthConnection:Disconnect()

also im trying to find a way to ungod myself!

First off, don’t do a health checker. Use forcefields with visible = false.

That wont fully work if OP damages the player bu doing hum.health -= num.

Well then set maxhealth to inf and health to inf.

local runService = game:GetService("RunService")
local IsGod = false

--[[playeradded
if player in group check
if player "chatted" check
isGod = true

_G.Player = Player

]]


runService.Heartbeat:Connect(function()
	local plr = _G.Player
	local char = plr.Character
	
	if IsGod == true then
		if char then
			if char:FindFirstChild("Humanoid") then
				char:FindFirstChild("Humanoid").Health = 100
			end
		end
	end
end)

You could use something like this… Didn’t test it! Just wrote it out of memory so you might have to fix some things but you could use this.

hey man i got it solved! I will share the script if anyone wanna use it!

players.PlayerAdded:Connect(function(player)		
	if player:GetRankInGroup(Settings.Main.RoCore) >= Settings.Main.RequiredRank or Settings.Main.VipOwners == player.UserId then
		
		player.Chatted:Connect(function(message)
			message = string.lower(message)
			local splitMessage = string.split(message, " ")
			
			local humanoid = player.Character:WaitForChild("Humanoid")
			
			if splitMessage[1] == Settings.Fun.God then
				
				
				HealthConnect = humanoid.HealthChanged:Connect(function()
					HealthBool = true
					humanoid.Health = 100
					print(HealthBool)
				end)
				
			elseif splitMessage[1] == Settings.Fun.UnGod then
				HealthBool = false
				HealthConnect:Disconnect()
				humanoid.Health = 90
			end
			
				
		end)
	end
end)

1 Like