- How do i get Player from PlayerName?
local playername = "NEW_GODPOTATO1110"
local remoteEvent = game.ReplicatedStorage.RemoteEvent
remoteEvent:FireClient(playername) --I cant do this
So I want to know that how to get player from playername.
local playername = "NEW_GODPOTATO1110"
local remoteEvent = game.ReplicatedStorage.RemoteEvent
remoteEvent:FireClient(playername) --I cant do this
So I want to know that how to get player from playername.
local Player = Players:FindFirstChild(PlayerName)
The person above said something that will work, unless the player is not in the server yet. I reccomend doing something along these lines:
local playername = "name here"
local remoteEvent = game.ReplicatedStorage.RemoteEvent
wait(1)
if game:GetService("Players"):FindFirstChild(playername) then
local player = game:GetService("Players"):FindFirstChild(playername)
remoteEvent:FireClient(player)
else
print("Player ".. playername.." is not in the server")
end
You can avoid repeating yourself by assigning whatever FindFirstChild
returns to a variable.
local game = game
local players = game:GetService("Players")
local player = players:FindFirstChild(playerName)
if player then
--Do code.
else
--Do other code.
end
Thank you for helping me!!
It works!!
Thank you so muchhh