Hmm... think i understand what you're trying to do here. You're trying to get the players name for your server script to display it in your belt?
If so, I've written a little example on how you can use a RemoteEvent hooked up in a LocalScript inside the player and a server-side script that listens to that event...
Code:
ServerScript:
local Rs = game:GetService("ReplicatedStorage")
local REvent = Rs.RemoteEvent
REvent.OnServerEvent:Connect(function(player)
print("Player[",player.Name,"] Has Called me!")
end)
Local Script: (using a tool to activate this event!..)
local Rs = game:GetService("ReplicatedStorage")
local REvent = Rs.RemoteEvent
local Tool = script.Parent
Tool.Activated:Connect(function()
REvent:FireServer()
end)
If you want to pass more than the player to your server side script you just add it like this:
ServerScript:
local Rs = game:GetService("ReplicatedStorage")
local REvent = Rs.RemoteEvent
REvent.OnServerEvent:Connect(function(player, Val1)
print("Player[",player.Name,"] Has Called me! \n Val1 is [",Val1,"]")
end)
Local Script: (using a tool to activate this event!..)
local Rs = game:GetService("ReplicatedStorage")
local REvent = Rs.RemoteEvent
local Tool = script.Parent
Tool.Activated:Connect(function()
REvent:FireServer("Test!")
end)
Hope this helps! :)
5 comments
I had realized ServerScripts can't access LocalPlayers, would there be any work around, maybe a suggested line of code for firing a remotevent?
Is this the only line of code or is there other lines? Because we cannot really help you if we don't have a full understanding on what you're trying to create.
That is the only line
Can you explain what you are trying to make?
A nametag that has the players last name from a value in the LocalPlayer.