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

How to fix "FireClient: player argument must be a Player object"? [SOLVED]

What I wanted to do with my sword script is to damage Humanoids on touch. I also wanted it so that when the Humanoid it is touching dies, it fires a remote event. However when I try it, it doesn't work!

Here is my script:

local db = true
local tool = script.Parent.Parent
script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		if db == true then
			if humanoid.Health > 0 then
				humanoid:TakeDamage(34)
				script.Parent.Hit:Play()
			if humanoid.Health <= 0 then
			game.ReplicatedStorage.RemoteEvent:FireClient(tool.Parent)
			end
				db = false
				wait(0.45)
				db = true
			end
		end
	end
end)

Thank you!

1 comment

0

As stated u can only pass a argument as player when firing from the local script just make it a player.

1 answer

✓ Accepted answer

The first parameter of :FireClient has to be a player object, what you are adding is a character(AKA the model). Here is what I would do:

local player = game.Players:FindFirstChild(tool.Parent.Name)
if player then
	game.ReplicatedStorage.RemoteEvent:FireClient(player)
end

1 comment

0

thank you so much! I didnt thought about it that way, to get the player variable using "FindFirstChild"

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