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

When i press on this GUI, it gives me 100K+ Cash, when it's only supposed to give 2?

HELP:

When i press on this GUI, it gives me 100K+ Cash, when it's only supposed to give 2? It's very weird and i do not seem to really know what the problem is

EXTRA HELP:

If you want to be even cooler and help me even more, the GUI is visible to everyone?

SCRIPT:

local Player = game.Players.LocalPlayer

while true do
wait()
if Player.leaderstats.Cash.Value >= 50 then
	script.Parent.Visible = true

script.Parent.Activated:Connect(function()
	Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 2
end)
end

2 comments

0

is the parent a textbutton?

0

It's because the part where you connect to Activated is in the while loop which means you'll get thousands of connections which means +2*Amount of Connections

1 answer

✓ Accepted answer

I'm going to assume script.Parent is a TextButton or ImageButton.

local Player = game.Players.LocalPlayer

local deb = false

while Player.leaderstats.Cash.Value >= 50 and script.Parent.Visible == false do --basically consolidating your while loop
    wait()
    script.Parent.Visible = true
end

script.Parent.MouseButton1Down:Connect(function() --when the button is clicked do the function; don't use activated, i think that's where you went wrong.
    if not deb then
	 deb = true --debounce so that it doesnt just let you spam it and it gives a bunch of cash
   	 Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 2
   	 wait(.5) --how long it waits before you can click again and it gives you money
  	 deb = false
	 end
end)

Hope this helped!

2 comments

0

btw, if it answered your question, please accept it :)

0

There is nothing wrong with using Activated, the problem was that he listened to it in the while loop

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