I am trying to fire a remote event to a specific client with two values when a player hits a part, However, when I try to fire the remote event to the player, it returns the error “FireClient: player argument must be a Player object” I tried seeing if the player was returing as nil but the player is found. Here is the script:
local Trigger = script.Parent
local textList = {
"Test1",
"Another Test Message",
"A Third Test"
}
local num = 1
Trigger.Touched:Connect(function(hit)
local Char = hit.Parent
local plyr = game.Players:GetPlayerFromCharacter(Char)
print(plyr)
game.ReplicatedStorage.TextEvent:FireClient(plyr, textList, num)
end)
I don’t usually use remote events although it seemed it would be easiest if I used one in this scenario.
You need to check if the hit is a Character by checking for a Humanoid instance.
This way, we can verify if the parameter is a character and not just any BasePart that would trigger the signal.
local Trigger = script.Parent
local textList = {
"Test1",
"Another Test Message",
"A Third Test"
}
local num = 1
Trigger.Touched:Connect(function(hit)
if hit.Parent then
local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player then
game.ReplicatedStorage.TextEvent:FireClient(Player, textList, num)
end
end
end
end)