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

Kick script doesn't kick the player?

I have this script that kicks a player but it doesn't kick?

local gamepass = 0 -- Gamepass ID here
game.Players.PlayerAdded:connect(function(plr)
	if game:GetService('GamePassService'):PlayerHasPass(plr,gamepass) then
		
	elseif plr.UserId == 8021038 then
		
	elseif plr.UserId == 161916404 then
		
	else
	plr:Kick('No access.')
	end
end)

2 comments

0

The only error is this 'Something unexpectedly tried to set the parent of Player1 to NULL while trying to set the parent of Player1. Current parent is Players.'

0

maybe add a wait at the start

1 answer

✓ Accepted answer

What you're trying to do is not allowed, as you're trying to kick a player the moment they join. The reason this occurs is because you're trying to set the parent of something to something, while roblox itself is parenting the player to the Players service.

Simply typing in a wait() inside of the function should make it work.

(I've also compacted your if statment)

local gamepass = 0 -- Gamepass ID here
game.Players.PlayerAdded:connect(function(plr)
wait()
if not game:GetService('GamePassService'):PlayerHasPass(plr,gamepass) and plr.UserId ~= 8021038 and plr.UserId ~= 161916404 then
		plr:Kick('No access.')
	end
end)

3 comments

0

Why not have it when the player's character loads? What I mean is the CharacterAdded event. (CharacterAdded:Wait())

0

TheeDeathCaster has a point. Unless theevanegps2 has CharacterAutoLoads disabled.

0

There's no need for that.

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