Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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 :)

2 comments

0

Well I was using it for dialog because it's easier, but that might work as well :)

0

Guis are more useful, I think. You can do what you want with them, dialogs are pretty limited (and don't look professional;)

This discussion is preserved as it was. New answers, comments, and votes are closed.