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

Why won't localplayer arg pass to serverscript?

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

✓ Accepted answer

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.

3 comments

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

0

Figured it out thanks!

0

No problem!

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