Hi! So I was working on this script that basically gives you a gun once you buy it.
In this script I have various if-statements that check if the person has a gun permit and enough money.
How do I resolve this issue? I think that because it gives me the tool multiple times, it gets called multilple times, but I wouldn’t know where…
The script:
function sendConfirmation(gun, price, player, legal, realprice)
if legal == true then
confirmation.Undertitle.Text = "This gun will be legal, but may only be used in self-defense."
end
if legal == false then
confirmation.Undertitle.Text = "This gun will be illegal, if you are searched you may face prison time."
end
confirmation.PriceEtc.Text = "Gun: "..gun..", Price: "..price
confirmation.Visible = true
confirmation.Buy.Activated:Connect(function()
if player.Backpack:FindFirstChild("Gun permit") then
if player.leaderstats.Cash.Value == realprice or player.leaderstats.Cash.Value > realprice then
addGun(gun, price, player, legal, realprice)
closeConfirmation()
else
closeConfirmation()
end
else
closeConfirmation()
end
end)
confirmation.Close.Activated:Connect(function()
closeConfirmation()
end)
end
I can’t find any immediate clues as to what could be the problem, try adding a new line with a print function to the start of the onServerEvent function to see if it is being fired twice or not
It never gave the gun multiple times on the first purchase. It’s mostly when you buy the 2nd gun, you get the first gun you bought, when you buy the 3rd gun you get the 1st and 2nd gun bought.
This sounds similar to certain other issues I’ve had where variables weren’t being updated correctly, and since the initial “Gun” variable is from another script I believe that the bug is somewhere else than in the code that you sent here. I could be wrong tough. If you could send where the sendConfirmation function is being called from I might be able to help you further, however I need to leave soon so I need to continue later