Hi, I need help with my whitelist teleport script

I wanted this script to teleport players back if their username did not match the whitelisted names, if you are inside the brick (which will be put over an area) it will check if you are on the whitelist, if not then you get teleported back, but for some reason it just does not do it.

heres my script:

modelname="LobbyTP"
local Whitelisted = {["Name1"] = true,["Name2"] = true, ["Name3"] = true, ["Name4"] = true}
------------------------------------
function onTouched(part)
	if part.Parent ~= nil then
		local h = part.Parent:findFirstChild("Humanoid")
		if h~=nil then
			local teleportfrom=script.Parent.Enabled.Value
				if teleportfrom~=0  then
				if h==humanoid  then
					return
				end
				
				
				local teleportto=script.Parent.Parent:findFirstChild(modelname)

				if teleportto~=nil	and  h.DisplayName == not table.find(Whitelisted,h.DisplayName)  then
					
					local torso = h.Parent.Head
					local location = {teleportto.Position}
					local i = 1

					local x = location[i].x
					local y = location[i].y
					local z = location[i].z

					x = x + math.random(-1, 1)
					z = z + math.random(-1, 1)
					y = y + math.random(2, 3)

					local cf = torso.CFrame
					local lx = 0
					local ly = y
					local lz = 0

					script.Parent.Enabled.Value=0
					teleportto.Enabled.Value=0
					torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
				
					script.Parent.Enabled.Value=1
					teleportto.Enabled.Value=1
					print("Kicked out of The Rmmy Room")
					
				elseif h.DisplayName ==  table.find(Whitelisted,h.DisplayName) then
					print("Allowed in The Rmmy Room")
					
		end

				end
			end
		end
	end


script.Parent.Touched:connect(onTouched)

in your code doesn’t make sense

further you can replace things like

if x ~= nil then

with

if x then

Further try adding some prints to see where it goes wrong, it’s currently rather hard to read because of how messy it is.

1 Like
local players = game:GetService("Players")
local part = script.Parent
local whitelist = {"Name1", "Name2", "Name3", "Name4"}
local lobby = workspace:FindFirstDescendant("LobbyTP")

part.Touched:Connect(function(hit)
	if hit.Parent then
		if hit.Parent:FindFirstChild("Humanoid") then
			local character = hit.Parent
			local player = players:GetPlayerFromCharacter(character)
			local name = player.Name
			if not table.find(whitelist, name) then
				local HRP = character:WaitForChild("HumanoidRootPart")
				HRP.CFrame = lobby.CFrame
			elseif table.find(whitelist, name) then
				--do code
			end
		end
	end
end)
1 Like

Thanks! Do you mind sharing what was wrong in my code so I can better myself in the future?