Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i add the players username to this script?

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

6 comments

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.

0

Are you using a touched event?

0

I am not using a touched event. But where would I add game:GetService("Players").LocalPlayer.Name to my code?

0

This is in a normal Script btw, not a LocalScript

0

Or is there anyway I can use a variable from a local script, to a normal script?

0

I dont understand, are you using a remote event?

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.