Hi, I'm currently helping a friend build an Obby and I'm doing most of the scripting,

I have become stuck on the admin commands, so far I have got a working add admin and remove admin function, yet the teleport function (where admins can teleport themselves to a spesific level.

local m = {}

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg, r)
		if r then return end
		m.parse(msg,player)
	end)
end)

local dStore = game:GetService("DataStoreService")

m.database = dStore:GetDataStore("adminCommands")
m.adminList = {--user ID
	1377362727;
	-1;
}

m.commandStart = ":"

local aList
pcall(function()
	aList = m.database:GetAsync("adminList")
end)
if not aList then
	m.database:SetAsync("adminList",m.adminList)
	aList = m.adminList
end

function m.parse(msg,player)
	local playerIsAdmin
	for a,b in pairs(aList)do
		playerIsAdmin=b==player.UserId
		if playerIsAdmin then break end
	end
	if playerIsAdmin then
		if msg:sub(1,1)==m.commandStart then
			if #msg==1 then
				warn("Just Command Signature, Consider Inputting a Command")
			else
				local line = msg:sub(2,#msg)
				local command,arguments=nil,{}
				for a in line:gmatch("[%w%p]+") do
					if command==nil then command=a else table.insert(arguments,a) end
				end
				if m.commands[command] then
					m.commands[command](arguments,player)
				else
					warn("No Command Titled "..command.." Exists!")
				end
			end
		end
	end
end


m.commands={
	addAdmin=function(arg,caller)
		for a,b in pairs(arg) do
			if tonumber(b) then
				print("Added Admin "..b)
				table.insert(aList,tonumber(b))
				m.database:SetAsync("adminList",aList)
			else
				local userid=game.Players:GetUserIdFromNameAsync(b)
				if userid then
					print("Added Admin "..b)
					table.insert(aList,userid)
					m.database:SetAsync("adminList",aList)
				else
					m.warn("addAdmin","Player Name \""..b.."\" Is Not a Valid Player")
				end
			end
		end
	end;
	removeAdmin=function(arg,caller)
		for a,b in pairs(arg) do
			if tonumber(b) then
				print("Removed Admin "..b)
				for d,c in pairs(aList) do
					if c==tonumber(b) then
						table.remove(aList,d)
						break
					end
				end
				m.database:SetAsync("adminList",aList)
			else
				local userid=game.Players:GetUserIdFromNameAsync(b)
				if userid then
					print("Removed Admin "..b)
					for d,c in pairs(aList) do
						if c==userid then
							table.remove(aList,d)
							break
						end
					end
					m.database:SetAsync("adminList",aList)
				else
					m.warn("removeAdmin","Player Name \""..b.."\" Is Not a Valid Player")

				end
			end
		end		
	end;
	print=function(arg,caller)
		for a,b in pairs(arg) do
			print(b)
		end
	end;
	teleport=function(arg,caller)
		for a,b in pairs(arg) do
			if tonumber(b) then
				num = tonumber(b)
				local pointsService = game:GetService("DataStoreService")
				print(player)
				vlu = tonumber(player:waitForChild("leaderstats").Stage.Value)
				if num < vlu then
					misseq = vlu - num
					vlu = vlu - misseq
					game.LoadCharacter(player)
				else
					if num > vlu then
						misseq = num - vlu
						vlu = vlu + misseq
						game.LoadCharacter(player)
					else
						if num == vlu then
							m.warn("you are already on this level")
						end
					end
				end
					
					
				
			end
	--		print(game.Players.Player.userId)
		--	local DataStoreService = game:GetService("DataStoreService")
	--		local StageDataStore = DataStoreService:GetDataStore("StageData")
		--	local player = game:GetService("Players").userID
	--		print(player)
		--	local pointsService = game:GetService("PointsService");
			--pointsService:AwardPoints(player.UserId, -pointsService:GetGamePointBalance(player.UserId));
		end
	end
}


function m.warn(cmd,issue)
	warn("In Command"..m.commandStart..cmd.." Issue Occoured, Receipt: "..issue)
end


return m

this is the entire admin code ^^^

this is the non-working teleport function vvv

	teleport=function(arg,caller)
		for a,b in pairs(arg) do
			if tonumber(b) then
				num = tonumber(b)
				local pointsService = game:GetService("DataStoreService")
				print(player)
				vlu = tonumber(player:waitForChild("leaderstats").Stage.Value)
				if num < vlu then
					misseq = vlu - num
					vlu = vlu - misseq
					game.LoadCharacter(player)
				else
					if num > vlu then
						misseq = num - vlu
						vlu = vlu + misseq
						game.LoadCharacter(player)
					else
						if num == vlu then
							m.warn("you are already on this level")
						end
					end
				end
			end
		end
	end

the error comes from when trying to fetch the player and returns as nil As this part is the problem I am yet to discover whether the code after works. If you know how I should fix this, please let me know

Thanks in advance.

2 comments

0

how is the player identified in the function? if its underlined, it means either no variable actually exists or you're calling a global in an enclosing function. i recommend putting the code inside the .Chatted event so you don't get something like this.

0

Please credit Spooks HD for this program