Whitelist for speed

I’m trying to make it so only people I choose get extra speed, for some reason it’s not working. If you could point me in the right direction that would help a lot, thanks.

local Whitelist = {"player","player"}

game.Players.PlayerAdded:Connect(function(plr)
for i, v in pairs(Whitelist) do
    if game.Players.LocalPlayer.UserId == game.Players:GetUserIdFromNameAsync(v) then
		  plr.CharacterAdded:connect(function(char)
			char.Humanoid.WalkSpeed = 18
		end)          
	end
end
end)

I am not sure, but I think you can’t get the user id from name by local scripts. You can use remote functions to return the value or just do this in a server script, and without the local player.

--Server script:
local Whitelist = {"player","player"}

game.Players.PlayerAdded:Connect(function(plr)
	for i, v in pairs(Whitelist) do
		if plr.UserId == game.Players:GetUserIdFromNameAsync(v) then --Check if the player that joins has the chosen id
			--give them speed.
		end
	end
end)
1 Like

plr.CharacterAdded does not return a character when a character is added to that specific player.
So you have to do something like this every time a character is added:

local char = plr.Character
if char then
  char.Humanoid.WalkSpeed = 18
end
1 Like

Hey, are you sure that it doesn’t return you the character? The character is in the parameters, and by doing characterAdded, you can change that every time the player spawns.
That’s what I understood.

I’ve had problems in the past with characterAdded not returning character.
So I used local char = plr.Character
It’ll probably be very embarassing if that was not the case.

Oh yeah, just realized your post might 99% be the solution. :upside_down_face:

1 Like

How do I give the speed? That’s where I’m stuck at, thanks.

LIke you did here.
That’s the same, and also, connect is deprecated, so you might want to change it to :Connect()

2 Likes