im trying to add an owner system to these suitcases with values, but it gives the error “instance is not a supported attribute type.” is there any workaround to get this to work? im fairly new to scripting, so feel free to let me know anything i should change in my script:
Hey there,
could you sent me the script so I can modify it? Oh, and could you explain more in detail what you want to achieve?
Thank you!
EDIT: oh and can you show us what in the folder?
If you are trying to add an owner attribut to check if a player is the owner, I think you could add a value to the player with the player ID. Everytime the owner joins with the Id you could give him a value “owner”.
Thats easier and I think you cant give the players name an Attribut
Not sure what you want to achieve, but try this:
local Folder = workspace.suitcases
function onPlayerAdded(player)
local playername = game.Players:FindFirstChild(player.Name)
print(playername)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("owner") == nil then
v:SetAttribute("owner", playername)
end
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
im trying to achieve an owner system for these suitcases so that when a player joins the game they get their own suitcase that then becomes visible, and when they leave, the suitcase that they owned will become invisible again and ownerless. im currently trying to use attributes as i was recommended in this post:Need help making multiple scripts with similar code run correctly by AusRin0177
suitcasescript.lua (383 Bytes)
also you got a lil problem in here instead of “nil” replace it with nil
local Folder = workspace.suitcases
function onPlayerAdded(player)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("Owner") then
v:SetAttribute("Owner", player.Name)
else
v:SetAttribute("Owner", player.Name)
end
end
end
function onPlayerRemoving(player)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("Owner") then
v:SetAttribute("Owner", nil)
end
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerAdded:Connect(onPlayerRemoving)
would this save who the owner is though? im trying to have its owner reset once they leave the game
i dont get any errors but it doesnt seem to change the attribute to the players name
local Folder = workspace.suitcases
function onPlayerAdded(player)
local playername = game.Players:FindFirstChild(player.Name)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("owner") == nil then
v:SetAttribute("owner", playername)
end
end
end
function onPlayerRemoved(player)
local playername = game.Players:FindFirstChild(player.Name)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("owner") == playername then
v:SetAttribute("owner", nil)
end
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerRemoved)
Also, where is the Attribute located?
oopsie i forgot to make it player.Name
each model has an attribute attached to it
i fixed the code above you can try again instead of player.Name i did put playername mb
Try if this works, also maybe use :GetDescendants() instead of :GetChildren() because The Attributes are located in the Models, not in the Folder.
it doesnt seem to change any of the attributes
this almost works but it creates a new attribute instead of updating the existing one, would it be possible to make it update the existing one?
you just gotta check if there is already an attribute that exists, if so it gets changed
Edited The Code.
i believe that SetAttribute() creates an attribute if there wasn’t an existing one, but if there is already an existing one it updates it.
local Folder = workspace.suitcases
function onPlayerAdded(player)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("Owner") and v:GetAttribute("Owner") == nil then
v:SetAttribute("Owner", player.Name)
end
end
end
function onPlayerRemoving(player)
for i,v in pairs(Folder:GetChildren()) do
if v:GetAttribute("Owner") and v:GetAttribute("Owner") == player.Name then
v:SetAttribute("Owner", nil)
end
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerAdded:Connect(onPlayerRemoving)
I think adding a check function if the suitcase is owned or not would be necessary here