Hello! I've been trying to make an inventory script (with slots for wearing items) and there are 2 slots for weapons which are named "Weapon1" and "Weapon2". They weren't working in online mode because i was creating them locally (I have filtering enabled) and the server didn't see it, so i moved the code that creates them to a serverside script and im completely baffled.
local weps = {"Weapon1","Weapon2"} Players.PlayerAdded:connect(function(plyr) ---OTHER STUFF--- for i,v in pairs(weps) do print("weps") local c = Instance.new("Folder",plyr.Character) c.Name = v if c then print(c.Name) end end ----OTHER STUFF---- end)
So, for some reason c exists (because it prints the name of c) but the folders aren't inside the character, I changed the destination to workspace and it created the folders. Like this:
local c = Instance.new("Folder",workspace)
The folders actually appear in the workspace but when i change the destination to the character like this:
local c = Instance.new("Folder",workspace) c.Parent = plyr.Character
The folders are just nowhere. I have NO idea how the heck this happening...
I solved it.. It was creating the folders before the character was actually created.
You do not need the PlayerAdded
event. Just use an LocalScript
on StarterPlayerScripts
(at starterPlayer)
local weps = {"Weapon1","Weapon2"} for i,v in pairs(weps) do print("weps") local c = Instance.new("Folder",game.Players.LocalPlayer.Character) -- gets the character and inserts the folders c.Name = v if c then print(c.Name) end end
It does not need anything to run. It runs once a player appears.