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

How can I make this script sell the weapons as well?

Asked by 8 years ago

Okay so I have made the script to be able to buy the weapons, but I can't figure out how to make it sell the weapons as well, in case a player makes the wrong purchase.

local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)

    local stats = player:FindFirstChild('leaderstats')
    if not stats then return end 

    local Gold = stats:FindFirstChild('Gold')
    if not Gold then return end 
    if choice == script.Parent.DialogChoice.ChoiceA then
        if Gold.Value >= 20 then             
            game.Lighting.Brown:Clone().Parent = player.Backpack
            Gold.Value = Gold.Value - 20
        end
    elseif choice == dialog.DialogChoice.ChoiceB then
        if Gold.Value >= 40 then            
            game.Lighting.Arion:Clone().Parent = player.Backpack
            Gold.Value = Gold.Value - 40        
        end
    elseif choice == dialog.DialogChoice.ChoiceC then        
        if Gold.Value >= 1000 then
            game.Lighting.Trail:Clone().Parent = player.Backpack
            Gold.Value = Gold.Value - 1000

        end
    elseif choice == dialog.DialogChoice.ChoiceD then
        if Gold.Value >= 2000 then            
            game.Lighting.Overlord:Clone().Parent = player.Backpack
            Gold.Value = Gold.Value - 2000                  
       end
    end
    end)

Thanks if you read this and double thanks if you reply

1 answer

Log in to vote
1
Answered by 8 years ago

Simply reverse it; but there is a problem. You need experience with guis to be able to do this. You need to make a gui that lists all of the chosen items. Here is what you do to sell, though:

local tax = 5 -- percentage, remove if you don't want. 
local button = script.Parent
local item = game.Players.LocalPlayer.Backpack:FIndFirstChild(button.ItemName.Value)
local cost = item.Cost
local stats = game.Players.LocalPlayer:FindFirstChild("leaderstats")
local g = stats:FindFirstChild("Gold")

button.MouseButton1Down:connect(function()
    if g and item then
        g = g + cost.Value
        item:remove()
    end
end)

Note: I made this to be used in a gui.

Hope I helped :)

0
Well I was using it for dialog because it's easier, but that might work as well :) STICKYBUN10 19 — 8y
0
Guis are more useful, I think. You can do what you want with them, dialogs are pretty limited (and don't look professional;) TheDeadlyPanther 2460 — 8y
Ad

Answer this question