I am trying to make a store for my game. There are no errors, but for some reason when I test it only the number values save and the bools do not work. I made sure that the script is getting called (because the points are working), but I have no idea why the bool values in the new folder created in game dont get their save data values. Model - Roblox here is a model including all three of the script for the store and save data. Script go in scriptserverservice and storeGui goes in starter gui. (there is a local script in store gui that changes the bool values when item is pruchased)
Can you please write out the scripts
Local script
local sP = script.Parent
local playerId = game:GetService(“Players”).LocalPlayer.UserId
local folder = workspace:WaitForChild(playerId)
–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 name1 = nil
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
if item.isItem.Value == true then
name1 = "It"
else
name1 = "Up"
end
folder:WaitForChild(name1 .. item.Name).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 name2 = nil
local function updateShop()
for i = 1, 8, 1 do
if i <= 4 then
name2 = “It”
else
name2 = “Up”
end
print(name2 … i)
if folder:WaitForChild(name2 … i).Value == true then
updateItem(sP.Store:FindFirstChild(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)
leaderboard
local data = game:GetService(‘DataStoreService’)
function newPlayer(player)
local saveData = data:GetDataStore('saveData', player.UserId)
local points = saveData:getAsync('Points')
local stats = Instance.new('Model', player)
stats.Name = 'leaderstats'
local pointStat = Instance.new("IntValue", stats)
pointStat.Name = 'Points'
pointStat.Value = points or 0
--Creates folder for values
local newItemFolder = Instance.new('Folder', workspace)
newItemFolder.Name = player.UserId
--SwuvleItem ID: 1
local ownsSwuvle1 = saveData:getAsync('OwnsSwuvleIt')
local ownsSwuvleItem = Instance.new('BoolValue', newItemFolder)
ownsSwuvleItem.Name = 'It1'
ownsSwuvleItem.Value = ownsSwuvle1 or false
--SniperItem ID: 2
local ownsSniper1 = saveData:getAsync('OwnsSniperIt')
local ownsSniperItem = Instance.new('BoolValue', newItemFolder)
ownsSniperItem.Name = 'It2'
ownsSniperItem.Value = ownsSniper1 or false
--MedkitItem ID: 3
local ownsMedkit1 = saveData:getAsync('OwnsMedkitIt')
local ownsMedkitItem = Instance.new('BoolValue', newItemFolder)
ownsMedkitItem.Name = 'It3'
ownsMedkitItem.Value = ownsMedkit1 or false
--DynamiteItem ID: 4
local ownsDynamite1 = saveData:getAsync('OwnsDynamiteIt')
local ownsDynamiteItem = Instance.new('BoolValue', newItemFolder)
ownsDynamiteItem.Name = 'It4'
ownsDynamiteItem.Value = ownsDynamite1 or false
--SwuvleUpgrade ID: 5
local ownsSwuvle2 = saveData:getAsync('OwnsSwuvleUp')
local ownsSwuvleUpgrade = Instance.new('BoolValue', newItemFolder)
ownsSwuvleUpgrade.Name = 'Up5'
ownsSwuvleUpgrade.Value = ownsSwuvle2 or false
--SniperUpgrade ID: 6
local ownsSniper2 = saveData:getAsync('OwnsSniperUp')
local ownsSniperUpgrade = Instance.new('BoolValue', newItemFolder)
ownsSniperUpgrade.Name = 'Up6'
ownsSniperUpgrade.Value = ownsSniper2 or false
--MedkitUpgrade ID: 7
local ownsMedkit2 = saveData:getAsync('OwnsMedkitUp')
local ownsMedkitUpgrade = Instance.new('BoolValue', newItemFolder)
ownsMedkitUpgrade.Name = 'Up7'
ownsMedkitUpgrade.Value = ownsMedkit2 or false
--DynamiteUpgrade ID: 8
local ownsDynamite2 = saveData:getAsync('OwnsDynamiteUp')
local ownsDynamiteUpgrade = Instance.new('BoolValue', newItemFolder)
ownsDynamiteUpgrade.Name = 'Up8'
ownsDynamiteUpgrade.Value = ownsDynamite2 or false
end
game.Players.PlayerAdded:Connect(newPlayer)
savedata script
–Made by Its4Realzies
local data = game:GetService(‘DataStoreService’)
function savePlayerData(player)
local saveData = data:GetDataStore('saveData', player.UserId)
saveData:setAsync('Points', player.leaderstats.Points.Value)
local playerFolder = workspace:FindFirstChild(player.UserId)
--Items
saveData:setAsync('OwnsSwuvleIt', playerFolder.It1.Value)
saveData:setAsync('OwnsSniperIt', playerFolder.It2.Value)
saveData:setAsync('OwnsMedkitIt', playerFolder.It3.Value)
saveData:setAsync('OwnsDynamiteIt', playerFolder.It4.Value)
saveData:setAsync('OwnsSwuvleUp', playerFolder.Up5.Value)
saveData:setAsync('OwnsSniperUp', playerFolder.Up6.Value)
saveData:setAsync('OwnsMedkitUp', playerFolder.Up7.Value)
saveData:setAsync('OwnsDynamiteUp', playerFolder.Up8.Value)
end
game.Players.PlayerRemoving:Connect(savePlayerData)