I am making a shop that has saves when you leave, but when trying to update the shop when the player joins I am having issues getting the values. (Inside updateShop function)
–Made by Its4Realzies with help from zamd157 and
local sP = script.Parent
local player = game:GetService(“Players”).LocalPlayer
–Text colors
local red = Color3.fromRGB(221, 57, 57)
local yellow = Color3.fromRGB(245, 184, 41)
local grey = Color3.fromRGB(145, 145, 145)
–Lock, Unlock and Own item
local function updateItem(item, status)
local parentFrame = item
if status == "Owned" or status == "Locked" then
parentFrame.BuyButton.TextColor3 = grey
parentFrame.Info.TextColor3 = grey
parentFrame.Title.TextColor3 = grey
parentFrame.Pic.Image = parentFrame.Pic.Unsaturated.Value
if status == "Owned" then
parentFrame.BuyButton.Text = "Owned"
parentFrame.isOwned.Value = true
else
parentFrame.BuyButton.Text = "Locked"
parentFrame.isLocked.Value = true
end
else
parentFrame.BuyButton.TextColor3 = yellow
parentFrame.Info.TextColor3 = yellow
parentFrame.Title.TextColor3 = yellow
parentFrame.Pic.Image = parentFrame.Pic.Saturated.Value
parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
parentFrame.isLocked.Value = false
end
end
–Updates items in shop to owned if they are owned
local name = nil
local function updateShop()
for i = 1, 8, 1 do
if i <= 4 then
name = “It”
else
name = “Up”
end
if player:FindFirstChild(name .. i).Value == true then
updateItem(i, "Owned")
end
end
end
updateShop()
local waitCheck = false
local function doPurchase(button)
local parentFrame = button.Parent
local player = game:GetService("Players").LocalPlayer
local leaderstats = player.leaderstats
local pointStat = leaderstats and leaderstats:FindFirstChild("Points")
local isOwned = parentFrame.isOwned.Value
local isLocked = parentFrame.isLocked.Value
if isOwned ~= true and isLocked ~= true then
if pointStat.Value >= parentFrame.Cost.Value then
updateItem(parentFrame, "Owned")
pointStat.Value = pointStat.Value - parentFrame.Cost.Value
--Unlocks upgrade
if parentFrame.isItem.Value == true then
updateItem(sP.Store:FindFirstChild(parentFrame.Name + 4), "Unlocked")
end
elseif waitCheck ~= true then
waitCheck = true
parentFrame.BuyButton.TextColor3 = red
parentFrame.BuyButton.Text = "Insufficient pts"
wait(1)
waitCheck = false
parentFrame.BuyButton.TextColor3 = yellow
parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
end
end
end
for i, button in ipairs (sP.Store:GetDescendants()) do
if button.ClassName == 'TextButton' and button.Name == "BuyButton" then
button.MouseButton1Click:Connect(function() -- Give it an anonymous function
doPurchase(button) -- Fire the function with the button parameter
end)
end
end
local shopEnabled = false
–Open and close shop
local function doOpenShop()
if shopEnabled == false then
shopEnabled = true
sP.Store.Visible = true
else
shopEnabled = false
sP.Store.Visible = false
end
end
sP.StoreButton.MouseButton1Click:Connect(doOpenShop)