Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help with this error "FireClient: player argument must be a Player object"?

I need help fixing this error. I don't think the remote event will take "player".

The error is "FireClient: player argument must be a Player object"

Here is the script

local part = script.Parent
local player = game.Players.LocalPlayer

local debounce = false

part.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
	if debounce == false then
		debounce = true
		game.ReplicatedStorage.GreenArrow:FireClient(player)
	end
end)

1 comment

0

Is this a LocalScript or a Script? In Script, not LocalScript, game.Players.LocalPlayer is nil. local player = game.Players:GetPlayerFromCharacter(hit.Parent)

1 answer

You can't use localplayer from a serverscript, and if this is a localscript, you cant fireclient from a localscript.

This code will work

local PlayersService = game:GetService("Players")

local Remote = your.path.to.remote


part.Touched(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local Character = humanoid.Parent
		local Player = PlayersService:GetPlayerFromCharacter(Character)
		Remote:FireClient(Player)
	end
end)

1 comment

0

thanks but i think i fixed it by adding game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character)

This discussion is preserved as it was. New answers, comments, and votes are closed.