I’m trying to use Attributes to count how many ProximityPrompts the player triggers, but when I use :GetAttribute() to call them, it shows as nil, and when I put breakpoints in and checked my player, there were no attributes in the properties window.
I put breakpoints in the my :SetAttribute() script, and they appear just fine in the properties window.
The original script:
local plr = game:GetService("Players").LocalPlayer
plr:SetAttribute("shelves", 0)
plr:SetAttribute("spills", 0)
This part works fine, and the attributes appear in the property window.
When debugging this script, they don’t appear:
local Folder = workspace.Products.ShelfSet2
local function Restock(plr)
for i, v in pairs(Folder:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = 0
script.Parent.Enabled = false
script.Parent.Parent = workspace.DisabledPrompts
local restock = plr:GetAttribute("shelves")
restock += 1
plr:SetAttribute("shelves", restock)
end
end
end
script.Parent.Triggered:Connect(function(plr)
Restock(plr)
end)
The first script appears to be a a local script, while the second script appears to be a server script. Changes made on the server script are not replicated to the client (however changes on the server are almost always replicated to the client).
If you move the :
code to a server script, either by adding it to a game.Players.PlayerAdded:Connect() function or modifying the
local plr = game:GetService("Players").LocalPlayer
plr:SetAttribute("shelves", 0)
plr:SetAttribute("spills", 0)
Second Script:
local Folder = workspace.Products.ShelfSet2
local function Restock(plr)
local restock = plr:GetAttribute("shelves")
if restock then
for i, v in pairs(Folder:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = 0
script.Parent.Enabled = false
script.Parent.Parent = workspace.DisabledPrompts
restock += 1
plr:SetAttribute("shelves", restock)
end
end
else
warn("Shelves attribute not found for player", plr.Name)
end
end
script.Parent.Triggered:Connect(function(plr)
if plr == game:GetService("Players").LocalPlayer then
Restock(plr)
end
end)