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

How to make the Random Item give just one item each time?

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)

--additional weapons

1 comment

0

try adding a CanGiveItem = true. if CanGiveItem == true and Player.leaderstats.Coins.Value >= amount then CanGiveItem = false --code--

2 answers

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)

local CanGiveItem = true

if CanGiveItem == true and Player.leaderstats.Coins.Value >= amount then

CanGiveItem = false --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)

--additional weapons

CanGiveItem = true

3 comments

0

Codeblock please.

0

Thanks for the response! However, its not quite working, Can you codeblock this? I'm not sure if this is working due to where I'm placing code, or where you are.

0

I added the debounce, no difference. =/ Any ideas?

Example:

local weapon = script.Parent.(Weapon Name)
----
wait()
---- code here.

Just an example of how the pro's do it. It should help... For more advice...copy scripts from like the "Item Giver" models.

3 comments

0

I tried to help ;( sorry it is bad.

0

:) thanks for the response, this has actually been solved as of several months back. But thank you for your time!

0

Your welcome :P

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