Getting reference to local player from a server script

What’s the most optimal way to get reference to the local player from a server script?
I have multiple server scripts in the workspace and I need each one to have reference to the local player, I tried using remote events but I can only connect the event to one script, and of course I shouldn’t add new remote event for every new script just to get reference to the local player

1 Like

Why do you need multiple scripts for each player?

Also, you can connect one remote to multiple scripts.

1 Like

I have something like this:
image

In every “Machine” there’s a “MachineModule”
In every “MachineModule” there’s the event connected:

When I fire “GetPlayerRefs” event in a local script, only one if the modules get the event connected and not all of them

1 Like

I solved this by adding an ObjectValue in ReplicatedStorage, then a remote event to fire in a local script, and I connected the event with the object value to store the player reference in the object value, now whenever a script need ref to the player I read it from the object value

2 Likes

You should probably just use one script to manage all of the machines

You can put the functionality of the machine module in a function and call that for each machine in a loop

It makes it easier to add more and you dont have to edit all of them individually

1 Like

But each machine has its own properties and values that change during runtime so each one needs a unique module, is there a better approach for that?

Yes

I see they have the same parts (base, cashier, distance detector, gui holder, machine stats, machine module), so they probably have the same functionality

You can made a function and then call the function for each machine with its own properties and values

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.