So 2 things that I notice are wrong at the moment. When I go into the game it does not make the PlayerData name file, and the equipped file. It is also not letting me open the GUI when I push the open Button. This is what I got so far.
Stats Script:
local datastores = game:GetService("DataStoreService") :getdatastore("CashDataStore")
local defaultcash = 50
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
local playerdata = Instance.new("Folder")
playerdata.Name = player.Name
playerdata.Parent = game.ServerStorage.PlayerData
local equipped = Instance.new("StringValue")
equipped.Name = "Equipped"
equipped.Parent = PlayerData
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = PlayerData
local player_data
local weaponsdata
local equippeddata
pcall(function()
player_data = datastores:getasync(player.userid.."-Cash")
end)
pcall(function()
weaponsdata = datastores:getasync(player.userid.."-Weps")
end)
pcall(function()
equippeddata = datastores:getasync(player.userid.."-EquippedValue")
end)
if player_data ~= nil then
--player has saved data , load it in
cash.value = player_data
else
Cash.Value = defaultcash
end
if weaponsdata then
--later
end
end)
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
datastores:setasync(player.userid.."-Cash",player.leaderstats.Cash.Vaule)
print("Saved")
playerLeft = playerLeft - 1
bindableEvent:fire()
end)
end)
game:BindToClose(function()
while playerLeft > 0 do
bindableEvent.Event:Wait()
end
end)
ServerHandler Script:
game.ReplicatedStorage:WaitForChild("GetTools").OnServerInvoke = function(player)
local items = {}
for _, object in pairs(game.ServerStorage:WaitForChild("Items"):GetChildren()) do
local itemProperties = {object.Name,object.Price.Value}
table.insert(items,itemProperties)
end
return items
end
Core Script:
-- Core UI localscript
local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools
local itemFrame = safeArea.ItemFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport
--[[
[ DO NOT WRITE YOUR CODE IN HERE. WRITE IT AT THE BOTTOM OF THIS SCRIPT. ]
If you want the rest of this code, become a Channel Member by going to https://www.alvinblox.com/join or
click on the Join Button next to the subscribe button on my YouTube channel.
I spend hours making these scripts and GUIs and I really appreciate your support - whether you subscribe, like or become members.
Thanks guys , you rock <3
Alvin
(This is a comment, you can delete it if you wish, but write any of your code below the following line, else it won't work.
--]]
-- WRITE YOUR CODE AFTER THIS LINE, DO NOT PUT IT IN THE COMMENT
shopButton.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visable
end)
local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25
