Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Commands restriction (Admin Commands through functions)?

Okay so I'm working on simple admin commands. And I've ran into the problem where everyone is able to use the commands.

This is what I have so far:

function God(msg)
	Player = script.Parent.Parent
	  if Player.Name == "shockyman101" or "17jdillon" or "DeathPossession" then
		if msg == "God" or msg == "god" then
			Player.Character.Humanoid.MaxHealth = 1000000
			Player.Character.Humanoid.Health = 1000000
			Player.Character.Humanoid.Jump = true
          print("Player.Name Has been godded")
		end
	end	
end
script.Parent.Parent.Chatted:connect(God)

Everyone can use this command even with me putting the if Player.Name then line. I need to know that I did wrong. Thanks ~Shocky.

1 answer

Hmm, let me remake your script (I've been doing Admin Commands for along time now), also I posted this kind of coding on your other question;

local Admins = {} --This is where the Admins will be

local fucntion ChkAdmin(plr,str) --Here is the function where it'll check if the player is an Admin
for i = 1, #Admins do if plr:lower() == Admnis[i]:lower() then return true end end --If the player is an Admin, then the function will return it true
return false --If the player isn't, then it'll return false
end --The end to end the function

local function onChat(plr,msg) --Now, lets use this for the chatted commands

if not ChkAdmin(plr.Name,false) then return end --If the player is an Admin, then the Player will beable to use the command, but if not, then the player won't beable to use it :D

if msg:lower() == "god" then --If the player chatted 'god' then
if plr and plr.Character and plr.Character:FindFirstChild("Humanoid") then --If player exists, the Character exists, and Humanoid exists within Humanoid then
plr.Character.Humanoid.MaxHealth = 1/0 --I use 1/0 for infinite
plr.Character.Humanoid.Health = 9e9 --This will equal to, about, 9000000? :P
plr.Character.Humanoid.Jump = true --This will make the player Jump
end --The end to end the code for to check the requirements 'if' statement
end --The end to end the code for the chatted command

end --Now, this ends the 'onChat' function

local function AdminControl(plr) --Now, lets use a seperate function for the script
plr.Chatted:connect(function(msg) onChat(plr,msg) end) --This will connect 'onChat' to the player
end --The end to end the code for 'AdminControl'

game.Players.PlayerAdded:connect(AdminControl) --When a player joins, the script will connect 'AdminControl' to the player
for i,v in pairs(game.Players:GetPlayers()) do AdminControl(v) end --I use this as an just-in-case

Hope this helped!

1 comment

0

This did help but it dot more complicated then I was looking for. But thanks for the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.