Greetings fellow humans,
So to cut it short what I'm trying to do is "continue a parent using a variable" (I realise those are the wrong terms)
I have put the following code in a script:
game.Players.PlayerAdded:Connect(function(player) --this whole function works fine wait(1) pcall(function() local id = player.CharacterAppearanceId local model = Instance.new("Model",game.ReplicatedStorage.collector) model.Name = player.Name local Models = game.Players:GetCharacterAppearanceAsync(id) Models.Parent = model wait() for i,v in pairs(Models:GetChildren()) do v.Parent = model wait() end Models:Destroy() end) end) game.Players.PlayerRemoving:Connect(function(player) pcall(function() game.ReplicatedStorage.collector ..player.Name --problem starts here end) end)
On "game.ReplicatedStorage.collector ..player.Name" i want ..player.Name to become the player name (which you probably already gathered)
I hope this doesn't sound too confusing.
Thanks in advance.
Well, the solution for this is actually quite simple. You would do the same thing as if you were looking for a value inside a table:
tbl["key"]
just in this case, the formatting would be
Object["ChildName"]
So in your case, the fixed code would be:
game.ReplicatedStorage.collector[player.Name]
This is very similar to tables because roblox objects, in essence are UserData
values with a metatable
.
You can see an prime example of this by doing the following in the command bar:
print(getmetatable(workspace.Baseplate))
The metatable is locked
This implies that the Base Plate has a metatable, and a __metatable index that subsiquently locks said metatable.That metatable contains all of the properties and methods of that part.
If you have any prior experience with the newproxy
function, this may sound very familiar to you, as newproxy(true) returns a blank userdata value with an empty metatable(there isn't a metatable attached if you provided false as a parameter for newproxy)
Hopefully this Helped, Be sure to accept if it did!