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

Why does my whitelist for my UTG kick me when it used to work?

So, I have a utg for a game im making and I have a whitelist so that if someone were to try to use it without being whitelisted they get kicked, and last night when I tested it it worked, but now I added to the script to play a sound if they are whitelisted and now it doesn't work. I checked to make sure the names are correct and no typos and idk why it isnt working now.

script.Parent.Frame.Visible = false
local player = game.Players.LocalPlayer 
local AllowedPlayers = {'pokemon9master29','coolman2555555'}

for i = 1, #AllowedPlayers do
	if player.Name == AllowedPlayers[i] then
		script.Parent.Parent.SPTW1.Playing = true
		script.Parent.Frame.Visible = true
		script.NotWhitelsited.Playing = false
		script.Parent.NotWhitelisted.Visible = false
	else script.Parent.NotWhitelisted.Visible = true
		script.NotWhitelsited.Playing = true
		wait(0.1)
		player:Kick('You are not whitelisted and/or permitted to use JoJUTG')
	end
end

I have checked over everything and can't find the problem.

1 answer

✓ Accepted answer

Hey there, this script has a few flaws:

  • You're checking on the client(can be exploited easily)
  • You're using a numeric loop for a table(bad habit, and not needed)
  • The player gets kicked at the first instance that they are not whitelisted at.
  • You're using player names, instead of Ids, which is also a bad habit, in case someone changes their name.

As a solution:

  • Make a remote function in ReplicatedStorage, in my example its named VerifyRemote
  • Make a server script in Server Script Service
  • Keep the current localscript where it is

The server script should look like this: (I changed the names to their IDs for you)

local remote = game.ReplicatedStorage.VerifyRemote
local allowed = {
	[159722433] = true,
	[307527557] = true
}
game:GetService("Players").PlayerAdded:Connect(function(plr)
	if not allowed[plr.UserId] then
		remote:InvokeClient(plr,false)
		wait(.1)
		plr:Kick("You are not whitelisted and/or permitted to use JoJUTG")
	else
		remote:InvokeClient(plr,true)
	end
end)

And your localscript should now look like this:

local remote = game.ReplicatedStorage.VerifyRemote
local plr = game.Players.LocalPlayer 
script.Parent.Frame.Visible = false

remote.OnClientInvoke = function(result)
	if result then
		script.Parent.Parent.SPTW1.Playing = true
		script.Parent.Frame.Visible = true
		script.NotWhitelsited:Stop()
		script.Parent.NotWhitelisted.Visible = false
	else 
		script.Parent.NotWhitelisted.Visible = true
		script.NotWhitelsited:Play()
	end
end

Tell me if something doesn't work or you don't understand something.

I'd also like to mention since you're making some frames visible on the client, you'd probably want to have server checks to make sure that the user is on the allowed list to use anything restricted.

1 comment

0

I'd actually like to add that you could use a remote event here, since you're not doing much on the client, but either works fine.

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