This code is so when slock is on, only whitelisted people can get in without being kicked. When testing different users, they are still being kicked despite being whitelisted. Can someone help me out?
Code:
serverlock = false
local Whitelisted = {"KaylaPls","909zenka"}
local Remote = game.ReplicatedStorage.SlockUnslock
Remote.OnServerEvent:Connect(function(Player,LockVal)
wait()
print(LockVal)
if LockVal == "Locked" then
serverlock = true
end
if LockVal == "Unlocked" then
serverlock = false
end
end)
game.Players.PlayerAdded:Connect(function(Player)
if serverlock == true then
for i = 1, #Whitelisted do
print(Whitelisted[i])
if Player.Name == Whitelisted[i] then
print("Player is whitelisted")
break
elseif Player.Name ~= Whitelisted[i] then
Player:Kick("This event hasn't started yet!")
end
end
end
end)
It’s not necessary to put an elseif when you can just put else instead so this script should probably be correct
local Whitelisted = {"KaylaPls","909zenka"}
local Remote = game.ReplicatedStorage.SlockUnslock
Remote.OnServerEvent:Connect(function(Player,LockVal)
wait()
print(LockVal)
if LockVal == "Locked" then
serverlock = true
end
if LockVal == "Unlocked" then
serverlock = false
end
end)
game.Players.PlayerAdded:Connect(function(Player)
if serverlock == true then
for i = 1, #Whitelisted do
print(Whitelisted[i])
if Player.Name == Whitelisted[i] then
print("Player is whitelisted")
break
else
Player:Kick("This event hasn't started yet!")
end
end
end
end)
game.Players.PlayerAdded:Connect(function(Player)
if serverlock and table.find(Whitelisted, Player.Name) == nil then
Player:Kick("This event hasn't started yet!")
end
end)