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!
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.
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.