Hey guys, I am trying to make a shop GUI where you can equip and re equip the items you bought.
As well as this, I am trying to make it so the fact that you’ve bought an item can save, so after you buy an item and leave and re join the game, you can simply re equip that item.
I have no clue how to do this, so could you guys give me some help with adapting these scripts to make these things? Here are my scripts:
BUY BUTTON
local replicatedStorage = game:GetService("ReplicatedStorage")
local selectedItem = script.Parent.Parent.Parent:WaitForChild("SelectedItem")
local redColor = Color3.fromRGB(255,26,26)
local greenColor = Color3.fromRGB(2,234,111)
local timeDelay = 2
local success
script.Parent.MouseButton1Click:Connect(function()
-- Remote function request
success = false
if selectedItem.Value ~= nil then
success = replicatedStorage.CheckSale:InvokeServer(selectedItem.Value)
end
if success then
script.Parent.TextColor3 = greenColor
script.Parent.Text = "Purchased!"
wait(timeDelay)
script.Parent.Text = "Buy"
else
script.Parent.TextColor3 = redColor
script.Parent.Text = "Purchase Failed!"
wait(timeDelay)
script.Parent.TextColor3 = greenColor
script.Parent.Text = "Buy"
end
end)
Shop Script
local replicatedStorage = game:GetService("ReplicatedStorage")
local shopItems = game:GetService("ServerStorage"):WaitForChild("ShopItems") -- Where tools are held
replicatedStorage.GetInfo.OnServerInvoke = function(player,item)
return shopItems[item].Coins.Value
end
replicatedStorage.CheckSale.OnServerInvoke = function(player,item)
local price = shopItems[item].Coins.Value
if player.leaderstats.Coins.Value >= price then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - price
local gear = shopItems[item][item]:Clone()
gear.Parent = player.StarterGear
local gear = shopItems[item][item]:Clone()
gear.Parent = player.Backpack
return true
else
return false
end
end
Remotes
local replicatedStorage = game:GetService("ReplicatedStorage")
local selectedItem = script.Parent.Parent.Parent:WaitForChild("SelectedItem")
local selectedImage = script.Parent.Parent.Parent:WaitForChild("ItemDescription").SelectedImage
local selectedName = selectedImage.SelectedName
script.Parent.MouseButton1Click:Connect(function()
-- Remotefunction request
local price = replicatedStorage.GetInfo:InvokeServer(script.Parent.Name)
if price ~= nil then
selectedName.Text = price.." Coins"
selectedImage.Image = script.Parent.Image
selectedItem.Value = script.Parent.Name
end
end)
Thanks guys!
Contact me if you wanna help me - octavodad#9302