What am I trying to do?
I’m trying to receive a player name from a local script and then locate that player within the game.
What is the issue?
To do this, I’m passing the player’s name from the local script to the server-script using an event. This is working fine - I’m using print debugging to confirm that the player name has been received correctly. However, when I go to locate that player in the game using the name, I get an error - P prints as nil (shown below). I’m not entirely sure how to go about it. This is what I tried:
takeDamageEvent.OnServerEvent:Connect(function(player, target)
print(target, "received from client.")
local p = game:GetService("Players"):FindFirstChild(target)
print(p)
if p then
print("Player located.")
else
print("Player not located.")
end
end)
Target prints correctly as the player name that was received from the local script, however P prints as nil.
No, that’s not it. I originally had that although forgot to re-add it when I edited a few things for testing. Definitely not the issue. (Fixed the post.)
I have no idea what args you are passing in the target but from the looks of it it looks like target already defines the player so there’s no need for the variable p, try testing it without the p variable.
Marked as solution - it wasn’t to do with the space, although it was an issue with the target. It wasn’t being sent as a string, but as an instance - simple fix. Thanks!