If I make a local Instance.new and name it as a player's UserId as such;
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) local playerid = Instance.new("NumberValue", game.ReplicatedStorage.PlayerList) playerid.Name = player.UserId playerid.Value = 0 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:
local Players = game:GetService("Players") local RS = game:GetService("ReplicatedStorage") local ChageIDFunction_Name = "ChangePlayer_Value_Funtion" Players.PlayerAdded:Connect(function(player) local PlayerList = (function() local F = RS:FindFirstChild("PlayerList") if(F == nil) then F = Instance.new("Folder",RS) F.Name = "PlayerList" end return F end)() local ChangeIDFunct = (function() local FunctFdr = RS:FindFirstChild("RemoteFunctions") if(FunctFdr == nil) then FunctFdr = Instance.new("Folder",RS) FunctFdr.Name = "RemoteFunctions" end local Funct = FunctFdr:FindFirstChild(ChageIDFunction_Name) if(Funct == nil) then Funct = Instance.new("RemoteFunction",FunctFdr) Funct.Name = ChageIDFunction_Name end return Funct end)() ChangeIDFunct.OnServerInvoke = (function(player,value) local PlayerId = player.UserId local Chk = PlayerList:FindFirstChild(PlayerId) if(Chk ~= nil) then Chk.Value = value end end) local playerid = Instance.new("NumberValue", PlayerList) playerid.Name = player.UserId playerid.Value = 0 end)
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:
local RS = game:GetService("ReplicatedStorage") local PlayerList_Folder = RS:WaitForChild("PlayerList",5) local RemoteFunctions_Folder = RS:WaitForChild("RemoteFunctions",5) local Player = game.Players.LocalPlayer local MyId = Player.UserId local Chk = PlayerList_Folder:WaitForChild(MyId,5) local ChangePlayerIDValueFunct = RemoteFunctions_Folder:WaitForChild("ChangePlayer_Value_Funtion",5) while true do if(Chk ~= nil) then print("Found IT!!! \n MyId is [",MyId,"] and the stored value is [",Chk.Value,"]" ) else print("Nothings there... sleeping!") wait(1) end ChangePlayerIDValueFunct:InvokeServer(Chk.Value+1) wait() 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! :)