Problem with remote event

Code:

--//Server Script:
function clicked(click)
print(click.Name)
inventEvent:FireClient(click,click.Name)
clickdetector:Destroy()
end

clickdetector.MouseClick:Connect(clicked)

Output = 4TH4RV (my username)


--//LocalScript
inventEvent.OnClientEvent:Connect(function(hmm, plrwhoclick)
	print(hmm.Name)
	print(plrwhoclick)

Output = nil, nil

  1. What do you want to achieve?
    Pass data as arguments to the local script.

  2. What is the issue?
    When I try to do it and then print the console prints “nil”

  3. What solutions have you tried so far?
    I tried looking on devforum and have searched this on google.

I would try to go back to basics and just experiment with it on an empty test place.

This is what I have:

ServerScript

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CantAffordEvent = Instance.new("RemoteEvent", ReplicatedStorage)
CantAffordEvent.Name = "CantAffordEvent"

if Cost <= Money then
	CantAffordEvent:FireClient(Player)
end

PlayerGuiScript

local Frame = script.Parent

--setup client listen
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CantAffordEvent = ReplicatedStorage:WaitForChild("CantAffordEvent")

 --Start Offscreen 

Frame.Position = UDim2.new(0.5, 0, 0, -300)



local function OnCantAffordFired() --brings up the gui
	Frame:TweenPosition(UDim2.new(0.5, 0, 0.22, 0), nil, nil, 0.25, false) --my code to run
end


CantAffordEvent.OnClientEvent:Connect(OnCantAffordFired)

See if you have missed anything there.

Im not sure if you need to be using a remote event for a click detector as you should be able to use a local script.

the variable “hmm” would hold the string of click.Name and as you are not passing a third arg plrwhoclick is nil.

inventEvent.OnClientEvent:Connect(function(hmm, plrwhoclick)
2 Likes

Yep so the string “click.Name” does not have a name. Hmm would be a string. So there is no name. And yeah plrwhoclick message isn’t sent.

See the Client knows who it is. So the message of “click” is only for the server to know who to send the message to.

After it works out who to send the message to, it then has the message it sends.

The client skips the player name and the first message is the message that the server sent. Not the player name.

Yeah you nailed it. I was about to say that.

You can work around this issue.

You’re working with a click detector. You can already connect the event on the client, and it’ll work just the same way. (except it only detects clicks made by the local player). Unless you want to be detecting more players locally, you don’t need a remote for this.

1 Like

You are only sending one argument throught the RemoteEvent because the first one you set in the FireClient() is the player. The player argument doesn’t actually get sent through. This is what the parameters are: FireClient(Player, Arguemnts). For other referenecs please see this page: RemoteEvent | Documentation - Roblox Creator Hub

Here is the fixed code:

--//Server Script:
function clicked(click)
print(click.Name)
inventEvent:FireClient(click, click, click.Name)
clickdetector:Destroy()
end

clickdetector.MouseClick:Connect(clicked)
1 Like