Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Shop Saves The Players Purchase I Gives The Player His Old Purchase And The New One?

Asked by 3 years ago
Edited 3 years ago

So I made A Shop And Added A Confirm GUI But Its Kinda Broken And Saves The Last Purchase Of The Player And When The Player Buys Another Item He Buys His Item And The Old One As Well

What Happens Is Described Well In This Video https://youtu.be/FNA8Ok46OnA

This Is My Script That Goes In SSS

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Shopitem = ServerStorage.ShopItem
local debounce = false

local function checkprice(player, item)
    local price = Shopitem[item].Price
    return price.Value
end

ReplicatedStorage.getPrice.OnServerInvoke = checkprice

local function buyItem(player, item)
    local confirmframe = player.PlayerGui.Menu.Confirm
    local yesbutton = confirmframe.Yes
    local gold = player.leaderstats.Gold
    if gold.Value >= Shopitem[item].Price.Value then
        confirmframe.Visible = true
        yesbutton.MouseButton1Click:Connect(function()
            print("Success")
            gold.Value = gold.Value - Shopitem[item].Price.Value
            Shopitem[item]:Clone().Parent = player.StarterGear
            Shopitem[item]:Clone().Parent = player.Backpack 
            confirmframe.Visible = false
        end)
    else
        print("Unable To Buy")
    end
    local nobutton = confirmframe.No
    nobutton.MouseButton1Click:Connect(function()
        confirmframe.Visible = false
    end)
end

ReplicatedStorage.buyItem.OnServerInvoke = buyItem

In Case You Wanna Try This Is A Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

for key, object in pairs(script.Parent:GetChildren()) do
    if object:IsA("ImageButton") then
        local weopan = object.Name
        local price = ReplicatedStorage.getPrice:InvokeServer(weopan)
        local desc = script.Parent.Parent.Description

        object.Price.Text = price
        object.Name1.Text = object.Name
        object.MouseEnter:Connect(function()
            desc.Text = object.Desc.Value
        end)
        object.MouseLeave:Connect(function()
            desc.Text = "Hover Over An Item For Its Description"
        end)

        object.MouseButton1Click:Connect(function()
            local purchasesuccess = ReplicatedStorage.buyItem:InvokeServer(weopan)          
        end)
    end
end
0
The for loop inside the localscript or client is checking if its only an imagebutton try checking the name too bc then idk how to explain :) but it fires the same like the last one rihgt? maybe. cant explain lol acediamondn123 147 — 3y
0
ok now how do i check the name LOL kidsteve923 139 — 3y

Answer this question