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

Problem With Firing A RemoteEvent via to the Client?

I have a script, parented to a part. Here's the code:

local trapPart = script.Parent
 
local function onPartTouch(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		-- Set player's health to 0
		humanoid.WalkSpeed = 1
		humanoid.JumpPower = 0
		repeat
			humanoid.Health = humanoid.Health - 1
			wait(1)
		until humanoid.Health == 0
		print("Player has Died!")
		game.ReplicatedStorage.RemoteEvent:FireClient()
		wait(5)
	end	
end
trapPart.Touched:Connect(onPartTouch)

And the FireClient, is locating to a LocalScript parented to a TextButton, here's the script:

local button = script.Parent
button.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	player.Character.Humanoid.Health = 0
	game.ReplicatedStorage.RemoteEvent:FireServer() 
	game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() -- Detecting the FireClient
		game.ReplicatedStorage.RemoteEvent:FireServer()
	end)
	button.Visible = false
	repeat wait() until player.Character.Humanoid.Health == 100 
	button.Visible = true
end)

But for some reason, this is what comes in the output.

21:49:57.208 - Argument 1 missing or nil

Any help with this?

1 comment

0

Don't forget that the first argument in a remote event is always going to be the player

1 answer

RemoteEvent:FireClient takes two arguments: player and more args (optional)

Example:

Event:FireClient(player, a, b, c, d)

On the client:

Event.OnClientEvent:Connect(function(a,b,c,d)
	print("Remote event handled")
end)

I hope this helps :)

1 comment

0

Didn't work, error now is: FireClient: player argument must be a Player object.

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