If I make a local Instance.new and name it as a player's UserId as such;
1 | local Players = game:GetService( "Players" ) |
2 |
3 | Players.PlayerAdded:Connect( function (player) |
4 | local playerid = Instance.new( "NumberValue" , game.ReplicatedStorage.PlayerList) |
5 | playerid.Name = player.UserId |
6 | playerid.Value = 0 |
7 | end ) |
How can I address it from another script?
I tried game.ReplicatedStorage.PlayerList.(player.UserId), however, that doesn't work. I want the Instance.new to be tied to the player and I thought I would accomplish this by making the name of the object a player's UserId but by doing so I can't identify it in other scripts since it doesn't exist yet and that I don't know how to express the name of the Instance.new in another script (since player.UserId isn't working).
Updated with 2 new scripts to do what you ask! :)
Code Server script:
01 | local Players = game:GetService( "Players" ) |
02 | local RS = game:GetService( "ReplicatedStorage" ) |
03 | local ChageIDFunction_Name = "ChangePlayer_Value_Funtion" |
04 |
05 | Players.PlayerAdded:Connect( function (player) |
06 | local PlayerList = ( function () local F = RS:FindFirstChild( "PlayerList" ) if (F = = nil ) then F = Instance.new( "Folder" ,RS) F.Name = "PlayerList" end return F end )() |
07 | local ChangeIDFunct = ( function () |
08 | local FunctFdr = RS:FindFirstChild( "RemoteFunctions" ) |
09 | if (FunctFdr = = nil ) then |
10 | FunctFdr = Instance.new( "Folder" ,RS) |
11 | FunctFdr.Name = "RemoteFunctions" |
12 | end |
13 | local Funct = FunctFdr:FindFirstChild(ChageIDFunction_Name) |
14 | if (Funct = = nil ) then |
15 | Funct = Instance.new( "RemoteFunction" ,FunctFdr) |
Local Script: (Note when you run this code it will continually add on 1 to the current value you have stored in your playerid value!)
Code:
01 | local RS = game:GetService( "ReplicatedStorage" ) |
02 | local PlayerList_Folder = RS:WaitForChild( "PlayerList" , 5 ) |
03 | local RemoteFunctions_Folder = RS:WaitForChild( "RemoteFunctions" , 5 ) |
04 | local Player = game.Players.LocalPlayer |
05 |
06 | local MyId = Player.UserId |
07 | local Chk = PlayerList_Folder:WaitForChild(MyId, 5 ) |
08 | local ChangePlayerIDValueFunct = RemoteFunctions_Folder:WaitForChild( "ChangePlayer_Value_Funtion" , 5 ) |
09 |
10 | while true do |
11 |
12 | if (Chk ~ = nil ) then |
13 | print ( "Found IT!!! \n MyId is [" ,MyId, "] and the stored value is [" ,Chk.Value, "]" ) |
14 | else |
15 | print ( "Nothings there... sleeping!" ) |
16 | wait( 1 ) |
17 | end |
18 | ChangePlayerIDValueFunct:InvokeServer(Chk.Value+ 1 ) |
19 | wait() |
20 | end |
Obviously you would hook up the ChangePlayerIDValueFunct:InvokeServer()
inside a button or something that changed when you did an action kinda like adding to a score board etc...
Hope this helps! :)