✓ Accepted answer
So there's two options I see here: either you're using a Server Script, in which case you'd need the PlayerAdded event of the Players Service, or you're using a Local Script and you can use the LocalPlayer variable of the Players Service to get the Client.
Also, I'd suggest using the player's UserId as this is completely unique for each player, as opposed to their UserName, but i'll show you both.
Server Script Example #1
game:GetService("Players").PlayerAdded:Connect(function(player)
if player.UserId == 813309294 then
end
end)
Server Script Example #2
game:GetService("Players").PlayerAdded:Connect(function(player)
if player.Name == "UnrealTube" then
end
end)
Local Script Example #1
local player = game:GetService("Players").LocalPlayer
if player.UserId == 813309294 then
else
script:Destroy()
end
Local Script Example #2
local player = game:GetService("Players").LocalPlayer
if player.Name == "UnrealTube" then
else
script:Destroy()
end
For the Local Scripts, I'm destroying the script if the player doesn't match the players you want the script to be given to. These lines should appear before any code is run.
You can use "or" to add other players, or iterate over a table containing the player's name / userid and check if the name / userid matches before continuing your code.
1 comment
y not put the script to StarterPlayerScripts and is it a local script?