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

RemoteEvent: Argument 1 missing or nil?

Server Script:

script.Parent.ClickDetector.mouseClick:connect(function()
	local player = game.Players.LocalPlayer
	player.Backpack.addInv.add:FireClient("item")
end)

Client Script:

wait(1)
script:WaitForChild("add")

script.add.OnClientEvent:connect(function(stuff)
	print(stuff)
end)

Filtering Enabled is on

Just trying to make a script that communicates with the player when a block is clicked. From what I've seen with RemoteEvents, I'm trying to pass on the argument "item" with the script in the players backpack so it prints the parameter "stuff" as "item". However, it keeps giving me the error "argument 1 missing or nil" on line 3. Help?

2 comments

1

Uhh, did you mislabel the scripts?

0

no...i have a feeling that that is a bad thing however...

1 answer

✓ Accepted answer

This code cannot work for multiple reasons, 1st the ClickDetector event mouseClick is deprecated and should not be used, but there is a MouseClick even.

2nd LocalPlayer can only be used in a local script as a server script does not run on the client.

3rd To be able to fire a client we must know the player we want to send the request to, you can use fire all clients to send an event to all of the clients at once.

Lastly putting a remote event in the backpack will mean it gets deleted upon the players death which will also mean the event will not be connected.

Example (server script):-

script.Parent.ClickDetector.mouseClick:connect(function(plr) -- the player object is passed
	-- you should change the location of this event, it is commonly put in the replicated storage
    player.Backpack.addInv.add:FireClient(plr, "item") -- we add the player as a param
end)

Local script:-

script:WaitForChild("add").OnClientEvent:connect(function(stuff)
    print(stuff)
end)

I hope this helps.

1 comment

0

Thank you for the help!

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