Player username server sided

I need help trying to grab player username sercersided for my car spawned so it renamed there vehicle player names car and I can’t figure out how to get the players name to rename it

Screenshots

image
image

Code

Server Sided script

> local event = game.ReplicatedStorage.Username
> 
> event.OnServerEvent:Connect(function(Username)
> 
> local plr = Username
> 
> end)
> 
> script.Parent.MouseButton1Click:Connect(function(plr)
> 
> wait(5)
> 
> local a = script.Parent.Parent.Parent.Parent.Player.Value
> 
> -- plr.leaderstats.Money.Value = plr.leaderstats.Money.Value -500
> 
> local car = game.ServerStorage.Cars.Mustang:Clone()
> 
> car.Parent = game.Workspace.Vehicles
> 
> car.Name = plr.." Vehicles"
> 
> script.Parent.Parent.Parent.Parent.CarSpawn.Visible=false
> 
> end)```

**Local Script**

```script.Parent.MouseButton1Click:Connect(function(plr)

local username = game.ReplicatedStorage.Username

local player = game.Players.LocalPlayer

username:FireServer(player.Name)

script.Parent.Parent.Vehicle.Visible=true

local text = script.Parent.Parent.Vehicle

local default = "SPAWNING VEHICLE ("

local default2 = ")"

text.TextColor3 = Color3.fromRGB(255, 255, 255)

wait(1)

text.Text = default.."4"..default2

wait(1)

text.Text = default.."3"..default2

wait(1)

text.Text = default.."2"..default2

wait(1)

text.Text = default.."1"..default2

wait(1)

text.Text = default.."0"..default2

wait(1)

text.TextColor3 = Color3.fromRGB(38, 255, 14)

text.Text = "Succesfully Spawned!"

wait(3)

text.Visible=false

end)

Use a remote event connected to a local script. So you find the userId and then use a remote event and fire that Id to the server.

1 Like

Not working for me

Are you using a localscript or a server script? Because server scripts can access the:

GuiButton.MouseButton1Click:Connect(function()
end)

Could you be a more in-depth in what you are trying to do/can you provide the code to your original source in a code box for us to be able to help you fix this? Please check the guidelines and rules of the Developer forum before posting.

Server sided and the event is being fired locally

Is the button not working or is there an error?

Error from line 12.

Attempt to concatenation local plr. Grabbing the code for you all

the first parameter is always the player which fired it, that’s why it is not working. Try this:

so in the local script you do this:

blah:FireServer(player.UserId)

and in the server script:

blah.OnServerEvent:Connect(function(player, UserId)
    print(UserId)
end)

edit: oop, read your post wrong, just put copy and paste this into your server script:

 event.OnServerEvent:Connect(function(Username)
 
   local plr = Username.Name
   print(plr)
 
 end)

I don’t need there UserID I need there username

Change the:

 local plr = Username

to:

 local plr = Username.Name

Trying that right now…
(30 characters max and what blah blah)

you didn’t actually transfer it to the server, because the first parameter is the player who fired it, the second one is the one you fired e.g

local script

lol:FireServer("Yum")

server script

lol.OnServerEvent:Connect(function(player, String)
    print (player) -- prints the name of the player
    print(String) -- prints "Yum"
end)
1 Like

Local Script

script.Parent.MouseButton1Click:Connect(function(plr)

local username = game.ReplicatedStorage.Username

local player = game.Players.LocalPlayer

username:FireServer(player.Name) – think i did

script.Parent.Parent.Vehicle.Visible=true

local text = script.Parent.Parent.Vehicle

local default = “SPAWNING VEHICLE (”

local default2 = “)”

text.TextColor3 = Color3.fromRGB(255, 255, 255)

wait(1)

text.Text = default…“4”…default2

wait(1)

text.Text = default…“3”…default2

wait(1)

text.Text = default…“2”…default2

wait(1)

text.Text = default…“1”…default2

wait(1)

text.Text = default…“0”…default2

wait(1)

text.TextColor3 = Color3.fromRGB(38, 255, 14)

text.Text = “Succesfully Spawned!”

wait(3)

text.Visible=false

end)

Confused on what you mean.
(30 charactersaaaaaaa)

It tells me the username when I do print("") but I can’t use it in the script I still get the error.

I think I fixed it, Stupidly forgot to remove plr from script.Parent.MouseButton1Click:Connect(function(plr)
nope still get the error

Fixed finally and works

You don’t actually need the strings part, in fact, you don’t even need anything fired over, all you have to do is fireserver, and do player.Name(no need to define player again)