How could I make this script function correctly?
local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)
-- Check the player has a stats object
local stats = player:FindFirstChild('leaderstats')
if not stats then return end
2 | local gold = stats:FindFirstChild( 'Gold' ) |
3 | if not gold then return end |
5 | if choice = = script.Parent.DialogChoice.ChoiceA then |
6 | if gold.Value > = 5 then |
7 | game.ReplicatedStorage.Weapon 1 :Clone().Parent = player.Backpack |
game.ReplicatedStorage.Weapon1:Clone().Parent = player.StarterPack
gold.Value = gold.Value - 5 -- subtract the amount of gold you need to purchase
end
elseif choice == dialog.DialogChoice.ChoiceB then
if gold.Value >= 10 then
game.ReplicatedStorage.Weapon2:Clone().Parent = player.Backpack
game.ReplicatedStorage.Weapon2:Clone().Parent = player.StarterPack
gold.Value = gold.Value - 10
end
elseif choice == dialog.DialogChoice.ChoiceC then
if gold.Value >= 15 then
game.ReplicatedStorage.Weapon3:Clone().Parent = player.Backpack
game.ReplicatedStorage.Weapon3:Clone().Parent = player.StarterPack
gold.Value = gold.Value - 15
end
end
end)