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

Why won't localplayer arg pass to serverscript?

Asked by 8 years ago

I'm trying to pass the local player from a local script to a server script in workspace through a remote event, yet it is telling outputting "error: attempt to index local 'player' (a number value)

--serverscript
setDotEvent.OnServerEvent:connect(function(numDots, player)
char = player.Character--Error pointing to this line
--more code
end)

--localscript
game.Workspace.SetupDots:FireServer(NumDots, game.Players.LocalPlayer)

1 answer

Log in to vote
0
Answered by
DevChris 235 Moderation Voter
8 years ago

The player is already submitted when you send information to client over to the server. This would be the fix:


--serverscript setDotEvent.OnServerEvent:connect(function(player, numDots) -- The client automatically sends the player! Easy. if player and player.Character then local character = player.Character end --more code end) --localscript game.Workspace.SetupDots:FireServer(NumDots)

By the way, use "local" when you aren't using variables in a global scale. They will be moved to the top of the stack

Also, I recommend organising your events in a folder in ReplicatedStorage or some other place where both can access. Organization is key. Functionality will still be the same, just update where it points.

0
ok, i mean the roblox wiki tutorial stored them in workspace, but i get what you are saying, ill fix up my code then accept answer if it works dragonkeeper467 453 — 8y
0
Figured it out thanks! dragonkeeper467 453 — 8y
0
No problem! DevChris 235 — 8y
Ad

Answer this question