Hello! I am currently new to scripting and facing Problems. I am working on a script that gets the Players UserID and copies the ID into a Stringvalue, I tried making it but it gives me errors.
The Error says “attempt to index nil with ‘UserId’”
Ive tried looking on scriptinghelpers but it wasnt very helpful since it doesnt have alot of users online.
Also the StringValue is parented to StarterCharacterScripts as a normal Script, . This is the Code I made.
ID = script.Parent.Value
Player = game.Players.LocalPlayer.UserId
script.Parent.Value = Player
If somebody could tell me what I did wrong it would be very helpful since I am stuck with this problem now for over half a hour.
(Update, I have tried with a local script, it doesnt give any errors now (yay) but it still doesnt do anything)
When using scripts in the StarterCharacter or StarterPlayer folder the script must be a local script to work. All you have to do is replace the script with a local script. Don’t forget to mark this post as a solution if it helped!
That’s because it’s a Script, so it’s not on the client, therefore you won’t be able to define .LocalPlayer since it’s in the server. Do you mean something like this?
game.Players.PlayerAdded:Connect(function(player)
local stringValue = Instance.new("StringValue", player)
stringValue.Value = player.UserId
end)