hey
I want to load the players name in a textlabel but it doesnt work and i dont know whats the problem
this is the script i have
script.Parent.Parent.Parent.PlayerName.Text = game.Players.LocalPlayer.Name
hey
I want to load the players name in a textlabel but it doesnt work and i dont know whats the problem
this is the script i have
script.Parent.Parent.Parent.PlayerName.Text = game.Players.LocalPlayer.Name
Hello, try putting it in serverscriptservice, and local script…
i tried in the textlabel and in the serverscriptservice, its a local script
You have to enter the name, of your textlabel
the PlayerName is the name for the textlabel
--local script in StarterGui as an example
local player = game.Players.LocalPlayer
game.ReplicatedStorage.RemoteEvent:FireServer(player)
-- serverscript in textlabel
game.ReplicatedStorage.RemoteEvent.OnServerEvent(player)
script.Parent.Text = player
end)
The power of remote events!
I know, but did you enter the name of your textlabel?
yep, thats it, you have to enter in local script, and label, unless it wont work.
That’s a solution but wanted to add up something, the player
argument you are firing the server with is completely useless, the player
argument you’re using on the OnServerEvent
is the default parameter for that function to represent the player who fired the event.
What I mean by that:
-- We send the argument "player"
game.ReplicatedStorage.RemoteEvent:FireServer(player)
-- "player" is the default arguemnt you find on that function
-- "plr" is the argument we sent to the server aka this one --> FireServer(player)
game.ReplicatedStorage.RemoteEvent.OnServerEvent(player, plr)
So doing this would be the correct way to use get the player who fired in a OnServerEvent
:
--local
game.ReplicatedStorage.RemoteEvent:FireServer()
--server
game.ReplicatedStorage.RemoteEvent.OnServerEvent(player)
If it’s difficult to understand then here is an example:
What you are supposed to do:
--local
local MyNumber = 5
game.ReplicatedStorage.RemoteEvent:FireServer(MyNumber)
-- serverscript in textlabel
game.ReplicatedStorage.RemoteEvent.OnServerEvent(player, SentNumber)
print(player) -- would be the instance so you'd do player.Name
print(SentNumber) -- will print MyNumber which is 5
What you are doing:
--local
local MyNumber = 5
game.ReplicatedStorage.RemoteEvent:FireServer(MyNumber)
-- serverscript in textlabel
game.ReplicatedStorage.RemoteEvent.OnServerEvent(SentNumber)
print(SentNumber) -- will print the player who fired the event
-- Because the first parameter would be the default player who fired argument
Haha! I forgot but thanks for correcting me