Error I'm having trouble fixing

So I don’t know what happened with my code but when I try firing an event, it just gives me an error saying Argument 1 missing or nil. What’s wrong with it? It worked fine in other scripts…

Script:

s.Touched:Connect(function(touch)
	local h = touch.Parent:FindFirstChild("Humanoid")
	if h then
		local player = game.Players:GetPlayerFromCharacter(touch.Parent)
		if player then		
			-- unrelated code here
		end
		event:FireClient()
	end
end)

Can you please tell us how ‘event’ is defined?
Oh yeah and is it a local script or a normal script?

local event = game.ReplicatedStorage:WaitForChild("Sell")

And if you look at the code itself, event:FireClient() that’s for a normal script… you can’t do FireClient in a local script

1 Like
s.Touched:Connect(function(touch)
	local h = touch.Parent:FindFirstChild("Humanoid")
	if h then
		local player = game.Players:GetPlayerFromCharacter(touch.Parent)
		if player then		
			-- unrelated code here
		end
		event:FireClient(player)
	end
end)

the issue is that you need to specify what client you want to fire to

Like @schaap5347 has mentioned, the remoteEvent:FireClient() method requires you to pass a player value, like remoteEvent:FireClient(player). This is why your script is erroring. That’s all you need to fix the script.

1 Like

Try this :

s.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(touch.Parent)
		if player then		
			-- unrelated code here
		end
		event:FireClient()
	end
end)
s.Touched:Connect(function(touch)
	local h = touch.Parent:FindFirstChild("Humanoid")
	if h then
		local player = game.Players:GetPlayerFromCharacter(touch.Parent)
		if player then		
			-- unrelated code here
		end
		event:FireClient(player)
	end
end)

The FireClient call should go inside the if player then conditional statement (in case ‘player’ is nil).

I thought of trying this but I thought that it wouldn’t work so I skipped over it but oh well it worked. Thank you

1 Like