Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to properly add arguments to a remote?

Asked by 5 years ago
Edited 5 years ago

I was working on a clicker game, and I was trying to implement a click multiplier function like most clickers have.

game:GetService("ReplicatedStorage").PlsNo.Buy.OnServerEvent:connect(function(player, item)

if item == "DPC" then

    if player.leaderstats.Dogecoin.Value >= player.Assets.DPCPrice.Value then

        player.leaderstats.Dogecoin.Value = player.leaderstats.Dogecoin.Value - player.Assets.DPCPrice.Value

        player.Assets.DPC = player.Assets.DPC*2

        player.Assets.DPCPrice.Value = player.Assets.DPCPrice.Value*2

        end

    end

end)

Whenever I fire this remote with the argument "DPC", it returns "DPC is not a valid member of remote event" any help would be appreciated. Thanks.

PS: It indeed says OnServerEvent:connect(function(player, item) You cannot see the "player" but if you check via source code, you will see that it is actually there. That is not the issue.

0
Note that, unless you click view source, it does not show player before item. However, I can confirm it is indeed there. xForVowels 6 — 5y
0
lol dogeCoin TheluaBanana 946 — 5y
0
nothing seems out of place here, what about the way u fired the server? TheluaBanana 946 — 5y
0
did u accidentally add the player argument there? TheluaBanana 946 — 5y
View all comments (5 more)
0
There is nothing wrong with your script that I can see. How are you firing it? Eg. game.Replicated.PlsNo.Buy:FireServer('DPC') note. if your adding player when firing it. That's why its not working. Enomphia 39 — 5y
0
@Enomphia wrong DeceptiveCaster 3761 — 5y
0
The reason why it isn't working is because the first parameter passed by OnServerEvent is ALWAYS the player that triggered the RemoteEvent. So what you should really be doing in those parenthesis is (player, item). DeceptiveCaster 3761 — 5y
0
This means that "item" actually refers to the player, not "DPC". If it was the second parameter passed, then it would be "DPC". DeceptiveCaster 3761 — 5y
0
^That is not the case. Like I said in the first comment, you may not see the player before item, but i guarantee that it indeed IS player, item xForVowels 6 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hello! I'm BlackOrange3343 and I'll be helping you today.

I have noticed that the comments technically answer your question but I'll provide a code example just in case.

So, when firing to the server you can pass arguments inside the parameters but the order is a little different. When you do :FireServer() there is a invisible argument that sends the Player to the server. This tells the server which player has fired the event.

So, when firing arguments you have to be careful about the order.

local RemoteEvent = ...
local Button = ...
Button.MouseButton1Down:Connect(function()
    RemoteEvent:FireServer(Arg1) -- Arg1 is whatever you want to send
end)

On the server:

local RemoteEvent = ...
RemoteEvent.OnServerEvent:Connect(function(Player, Arg1)
    -- As you can see arg1 comes second. The first argument in the parameter will always be Player
end)

I'm not entirely sure where your error is because it seems like the error is not coming from the script you provided. When firing from the client your line should look like RemoteEvent:FireServer('DPC'). Make sure you are using the correct Remote Event and make sure there is no more then 1 OnServerEvent event. This might be triggering many code at once.

Next time please provide the line where it states the error and all the scripts that may be related to the issue.

Also make sure to match up the Arg1 and as you can see the order is moved over by 1.

If you do edit your question make sure to notify me, I'll get back to you as soon as possible.

Hopefully this helped!

Best of luck developer!

BlackOrange3343

PS: Use the comments that people have commented. They're useful.

Ad

Answer this question