Admin command script not getting past the PlayerAdded function?

Hey developers. For some reason, the following script is not working. I put some test prints through it so you can see what works and what doesn’t. It appears to stop at the PlayerAdded function. All help is appreciated. :slight_smile:


print("Script running") -- Printed

local commands = {}

commands.kill = function(target)
	target.Character.Humanoid.Health = 0
end

commands.ban = function(userId)
	
end

commands.unban = function(userId)
	
end

print("Test1") -- Printed

local adminDs = game:GetService("DataStoreService"):GetDataStore("AdminDatastore")

print("Test2") -- Printed

require(4874365424) -- // Require the module for the icons

print("Test3") -- Printed

game.Players.PlayerAdded:Connect(function(plr)

	print("Test4") -- Not printed

	wait(3)
	print(tostring(plr))  -- Not printed
	local data = adminDs:GetAsync("User-=-" .. plr.UserId) or {"Guest",  {(os.time() + 438765487365), 151814829, "Because you are a noob"}}
	local rankdata = data[1]
	local bandata = data[2]
	
	if bandata[1] ~= 0 and bandata[1] >= os.time() then
		print("Kick parameters met for " .. plr.Name)
		plr:Kick("You have been banned from this game! \n \n You were banned by:" .. game:GetService("Players"):GetPlayerByUserId(bandata[2]) .. " \n \n Reason given: " .. bandata[3] .. " \n \n If you feel this ban was not fair or accurate, please join our server and appeal with our ticket system.")
	end
end)

There are no errors btw.

This is probably due to your code taking too long to execute, leading to the event being connected after the player has entered the server.

In normal servers, a slight delay in execution time wouldn’t be a problem since there’s a few seconds/minutes between a server starting and a player joining the game. But because there’s no latency in Studio, even one second can result in the server not being ready when the player joins.

Try putting PlayerAdded at the top of the script with prints. If it works, then there’s a delay somewhere in the previous statements (probably the module or DataStore since it has to send requests to Roblox) that’s preventing the event from connecting in time.

2 Likes
local function chatted()

end

for _,v in pairs(plrs:GetPlayers())
    v.Chatted:Connect(chatted)
end

playeradded:Connect(function(plr)
    plr.Chatted:Connect(chatted)
end)

Would something like this work?
(Also I am a HUGE fan of yours… your game was the first game I ever played on roblox and I have literally admired you for years!!!)

Yep that method should work, just do that with a new onPlayerAdded function.

Thanks, I appreciate it :slight_smile:

2 Likes