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

Kicking a player when touching a brick, except if they're an admin?

local player = game:GetService("Players"):WaitForChild("LocalPlayer")
local admin = {"Player",
			   "Player2",
	
}

script.Parent.Touched:connect(function(hit)
	if hit.Name == "Humanoid" then
	for i,v in pairs(admin) do
		if player.Name == v then
			return admin
		else 
			if player.Name ~= v then
				player:Kick("You are not an admin")
			end
		end
	end
end
end)

So I wanted to make a script where if a player touches a brick and they're not in the admin table, they get kicked. If a player touches the same brick and they're in the admin table, then they don't get kicked and nothing happens to them. I wrote this code in a local script, and put it in the brick.

No errors showed in the output, and when I touched the brick, nothing happened.

2 comments

0

Please use code block.

0

Check the wiki on how to make a kill brick and how to make an admin door, then combine the two, basically.

1 answer

✓ Accepted answer

1st I would not kick a player using a localscript

2nd hit.Name would never be Humanoid except it the part which touched it is named Humanoid.

3rd I would not kick by player name as users can change their name

I would use UserId to check the player.

Some hits

You can get the player from the model by using this method GetPlayerFromCharacter

Then check the players UserId against a pre made table, using a table with keys will mean that you will not need to search for the players id.

Hope this helps.

1 comment

0

Good suggestions.

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