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

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

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

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?

2 comments

0

m8 your wrong. I figured out that I forgot to enable filtering enabled. But thx for writing this

0

actually doesnt work

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