Hello! I have a working random item giver in my shop. The only problem is it sometimes gives more than one item, and charges the player multiple times, when it should only be one click = one item. But it doesn't always do this, sometimes it works fine.
My random item giver also does not give duplicates. When the player presses the Buy button the script checks if the player already has a Bool Value that represents the item, if the player does not have the item the Remote fires the server and grants the item while removing the amount. And if the player already has the item, the description reads out a message saying as such and no charge is done.
How can I make it to where the script doesn't attempt to charge multiple times when the player presses the Buy button??
Script below:
local Item1Coinsbutton = script.Parent.Frame.CRATESFrame.Item1Frame.BuyCoins -- The Buy button.
script.Parent.Frame.CRATESFrame.Item1Frame.CoinsPrice.Text =100
Item1Coinsbutton.MouseButton1Click:Connect(function()
local amount =100
local descText = script.Parent.Frame.CRATESFrame.Item1Frame.DescriptionFrame.ItemDescription
local random = math.random(1,200)
if Player.leaderstats.Coins.Value >= amount then
--Item 1, checks to see if the player does not own the item, and then grants.
if random >0 and random <10 and Player.Inventory1.HasGunBlue.Value == false then
CoinsPurchase:FireServer(Player.Inventory1.HasGunBlue, amount)
descText.Text = 'You received Gun! Check your Blue Inventory!'
wait(3)
--Checks to see if the player does own Item 1, if they do, the description box will say so.
elseif random >0 and random <10 and Player.Inventory1.HasGunBlue.Value == true then
descText.Text = 'You received Gun Blue! You already own this item. Try again!'
wait(3)
--Item 2 checks to see if the player does not own, and then grants.
elseif random >11 and random <20 and Player.Inventory1.HasGunGreen.Value == false then
CoinsPurchase:FireServer(Player.Inventory1.HasGunGreen, amount)
descText.Text = 'You received Gun! Check your Blue Inventory!'
wait(3)
--Checks to see if the player does own Item 2, if they do, the description box will say so.
elseif random >11 and random <20 and Player.Inventory1.HasGunGreen.Value == true then
descText.Text = 'You received Gun Green! You already own this item. Try again!'
wait(3)
--Item3-20, etc.
end
end
wait(5)
Item1Frame.Visible = false
end)
end)

1 comment
uhh.