How to Get a localplayer from serverside

This is my problems for this topic

  1. What do you want to achieve? I want to get a local player instance from serverside using module scripts

  2. What is the issue? I cannot get a player object because it was a server side script

  3. What solutions have you tried so far? before sending a client to server (which is a server module scripts) i put a localplayer variable and try sending it to it but some how the result is nil

So just conclusion, Im making a placement system with a prompt that a owner of that plot can use it, i tried to debug first so i dont need to waste my time deleting all codes by printing hello world if the plot owner has triggered it. But when i tested, it doesnt work. I used objectvalue to determined that the player is a plot owner or not. And yes you can guess that the value of the objectvalue is empty so the script doesnt print out the result.On the client is working fine because you can get the localplayer but when you transfer to a server(module script), it appears to be nil

NOTE: i learn from a tutorial inside a forum because im not good at remote functions that much so it was hard for me

game.Players.PlayerAdded:Connect(function(player)
     -- your code here
      player.Backpack.Tool --example
      player.Position --example
end)

In the script above, “player” is the reference.

1 Like

I’ll try that later! Thank you!

yes this will work indeed. But whatever is in that piece of script will execute when the player is added. What if you want to just have a variable? I think that’s what he means. If not than sorry I am curious myself in knowing is it actually possible to make a variable in a script that references the localPlayer without having to make a connection and put player in the brackets as a parameter. :laughing:

1 Like

There is already a set variable…

game.Players.PlayerAdded:Connect(function(player)

You can simply put your OnServerEvent into said function.

2 Likes

right this is actually true! but what if you want to do something without a remote event? that’s what I meant. thanks for pointing out my mistakes.

How do you currently know which plot belongs to which user. Do you automatically give a user a plot when they join your game.
Or do they touch a part on the plot to claim it
Or something else?

Could we see your current code. Seeing your code might help us even more help you to fix your mistakes you might have made.

i got an error called
Requested module experienced an error while loading
the error starts when you require a module scripts

Sure! this is the line i got a problem

> function Placement:Place(model, cf, isColliding, player)
> 	if (not isColliding and isServer) then
> 		local clone = model:Clone()
> 		local owner = clone:FindFirstChild("Owner")
> 		print("Getting owner data")
> 		clone:SetPrimaryPartCFrame(cf)
> 		clone.Parent = self.CanvasObjects
> 		for i,v in pairs(clone:GetDescendants()) do
> 			print("Name:"..v.Name.." ClassName:"..v.ClassName)
> 			if v.Name == "Owner" and v.ClassName == "ObjectValue" then
> 				print("Found a owner objectvalue!")
> 			end
> 		end
> 		print(player)
> 		game.Workspace.TestDebug.Value = clone
> 		end
> 		
> 	if (not isServer) then
> 		invokePlacement:FireServer("Place", model, cf, isColliding)
> 	end
> 	end

model is the model of the placement,cf is the cframe of the position and rotation, is collide is an another function that checks if the object is collide with other object, and last a

player which are from my local script that sends a data to a module which results in a NIL

oh by the way, sorry for the late, i just got back from pinic!

I did a object value on every plot, so if players join i can set the plot value to the player, however if im putting the placement into a plot, then it will bug a lot.So,i prefer make a new storage.

Hmm this is interesting i’ll try that too!

Oh my god, it working now the module is printing out a player names!!!
Thank you! :heart_eyes: :heart_eyes: :heart_eyes: