Hey! I’m trying to get a player from game.Players using their names, but it keeps returning “nil”. Other thing to know is I’m trying to FireClient using their name through a server script.
I tried looking through the dev forum and Reddit and I can’t seem to find any solutions to my problem.
Here’s an example of my code:
local giveCashEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“GiveCash”)
local playerName = script.Parent.Owner.Value
local getPlayer = game.Players:FindFirstChild(playerName)
local Credits = math.Random(10,15)
giveCashEvent:FireClient(getPlayer, Credits)
local giveCashEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“GiveCash”)
-- should be
local giveCashEvent = game:GetService("ReplicatedStorage"):WaitForChild("GiveCash")
i’ve tried your script with by changing getPlayer/ Credits
local giveCashEvent = game:GetService("ReplicatedStorage"):WaitForChild("GiveCash")
local playerName = script.Parent.Owner.Value
local getPlayer = game.Players:WaitForChild(playerName, 10)
local Credits = math.random(10,15)
giveCashEvent:FireClient(getPlayer,Credits)
and it works!
i used print() to test if it really works to the client when it was fired
10 there is 10s timeout where if its been 10s and it doesn’t appear then the script will stop waiting for the child. studio take time to load all gui/ events and others so i put that there.
did you copy/ paste my code there? if not maybe check your capitalization and if it still doesn’t work can you show me the full error so i would know which line it is
Yea I copied and paste your code, still didn’t work. However I did already found a work around to my problem, so my script is working now, just a different way. Thank you for trying to help though, I really appreciate it!