Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i add the players username to this script?

Asked by 4 years ago
Edited 4 years ago

Im making a car, and I need to add the username of a player to a script in order for it to work. The car spawner script spawns the car in with the name "playersusername"sCar. So for example, when I spawn the car in, it would be named mcslimemansCar . I need to find out a way to insert a players username into this line of code.

local Car = workspace:FindFirstChild(--insert code here)

So what would i put inside of that slot? I want it to be playersusernamesCar but I can not figure out how to do it. I have tried adding

player.Name .. 'sCar'

into the slot, but it doesn't work. it says w001: Unknown global 'player'

The errors in the output are 13:00:47.339 - Workspace.mcslimemansCar.DriveScript:4: attempt to index nil with 'Name'

Any help would be appreciated

0
If the car is spawned through a remote event from the client to the server, you can just add "game:GetService("Players").LocalPlayer.Name" as a parameter to get their name. Fad99 286 — 4y
0
Are you using a touched event? NoahsRebels 99 — 4y
0
I am not using a touched event. But where would I add game:GetService("Players").LocalPlayer.Name to my code? mcslimeman 37 — 4y
0
This is in a normal Script btw, not a LocalScript mcslimeman 37 — 4y
View all comments (2 more)
0
Or is there anyway I can use a variable from a local script, to a normal script? mcslimeman 37 — 4y
0
I dont understand, are you using a remote event? User#30811 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Turns out i didnt need to add their username. I did local car = script.Parent instead of local car = mcslimemansCar. So instead of trying to find it in the workspace, it just finds the parent of the script, which is the car.

Ad

Answer this question