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

Why is the string not being passed as an argument into the server script?

Asked by 7 years ago
Edited 7 years ago

Local script:

clr is not a variable but from what I have read it does not have to be since it means player.

Target = mouse.Target.Name
print(Target)
InventoryIncrease:FireServer(clr,Target)
mouse.Target:Destroy()

Server script:

InventoryIncrease.OnServerEvent:connect(function(clr,Target)
    print(clr)
    print(Target)
    game.ServerStorage.Inventory[clr].InventoryStuff[Target].Value = game.ServerStorage.Inventory[clr][Target].Value + 1
end)

Output:

Grass
shabbs15
nil
16:00:35.901 - Workspace.Communication:40: bad argument #2 to '?' (string expected, got Object)
16:00:35.902 - Stack Begin
16:00:35.903 - Script 'Workspace.Communication', Line 40
16:00:35.903 - Stack End

As you can see, I pass the text "grass" to the server but it returns nil when I print in server. Filtering enabled is on as well.

1 answer

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

In remote events, whenever a client fires to the server, the player's name who fired it is always the first argument. I think you misunderstood the Wiki. You need not need to put a place holder variable for the player as the game will think it is another variable you need to pass. Example:

--Client script
RemoteEvent:FireServer(plrPlaceholder, data)
--Server script
RemoteEvent.OnServerEvent:connect(function(plrName, plrPlaceholder, data)
       print(plrName)--will print your name
       print(plrPlaceholder)--nil because it isn't a thing
       print(data)--will print your data
end

In remote events, the player name is always the first argument, you cannot put a place holder for it. Just remove the placeholder and it should work.

Edit: So the values passed should be: clr == player who fired; target == nil(nil because the plrPlaceholder was nil) so "grass" never gets a chance to be in the script because of only two arguments, not all the three being.. Uh... Recognized I guess?

0
m8 your wrong. I figured out that I forgot to enable filtering enabled. But thx for writing this shabbs15 67 — 7y
0
actually doesnt work shabbs15 67 — 6y
Ad

Answer this question