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

Why wont the clicks come through?

I tried to alter a script where when u click you get 1 click, but with 50 coins you can buy 1.5x clicks. Here is my script:

local button = script.Parent
local player = button:FindFirstAncestorOfClass("Player")
repeat
	player = button:FindFirstAncestorOfClass("Player")
	task.wait()
until player ~= nil

local debounce = true
button.MouseButton1Click:Connect(function()
	if debounce then -- if debounce is true
		debounce = false

		local leaderstats = player:WaitForChild("leaderstats")
		local Clicks = leaderstats:WaitForChild("Clicks")
		Clicks.Value += 1
		
		if game.StarterGui.Shop.ShopFrame.X1dot5.MouseButton1Click then -- here is what I add and it does not work
			if game.Players.LocalPlayer.leaderstats.Coins.Value == 50 then
				Clicks.Value +=0.5
			end
		end
				
			
		
		
		
		
		

		task.delay(0.5, function() -- after 1 second, debounce will turn true
			debounce = true
		end)
	end
end)

Thanks for helping!

1 comment

0

Try using prints to narrow down the issue like this print("Test")

2 answers

✓ Accepted answer

The script you're using is my script. What you did in line 17 is wrong. It won't work when you click the button only. It works because it checks if MouseButton1Click exists, which it does. What you will do is copy line 9.

Player.PlayerGui.Shop.ShopFrame.X1dot5.MouseButton1Click:Connect(function()

Also you can just put it outside button.MouseButton1Click.

Final script:

local button = script.Parent
local player = button:FindFirstAncestorOfClass("Player")
repeat
	player = button:FindFirstAncestorOfClass("Player")
	task.wait()
until player ~= nil

local debounce = true
button.MouseButton1Click:Connect(function()
	if debounce then
		debounce = false
		
		local leaderstats = player:WaitForChild("leaderstats")
		local Clicks = leaderstats:WaitForChild("Clicks")
		Clicks.Value += 1
		
		task.delay(0.5, function()
			debounce = true
		end)
	end
end)

local debounce2 = true
player.PlayerGui.Shop.ShopFrame.X1dot5.MouseButton1Click:Connect(function()
	local leaderstats = player:WaitForChild("leaderstats")
	local Clicks = leaderstats:WaitForChild("Clicks")
	local Coins = leaderstats:WaitForChild("Coins")
	
	if (Coins.Value >= 50) and debounce2 then
		debounce2 = false
		Clicks.Value += 1.5
		
		task.delay(0.5, function()
			debounce2 = true
		end)
	end
end)

1 comment

0

The repeat loop is pointless... The player will need to be loaded anyway in order for the script to load, as it is a descendant of the player.

first on line 2 you can do:

local player = game:GetService("Players").LocalPlayer

It works better and is more reliable. the repeat loop from line 3 to 6 can go, player is already defined and looping something over it is worthless.

to solve the actual issue you asked about try this:

on line 19 instead of:

Clicks.Value +=0.5

do:

Clicks.Value *=1.5

changing the + symbol to a * makes it multiply instead. we change 0.5 to 1.5 because otherwise you lose clicks.

1 comment

0

P.S. you may want to clarify what EXACTLY the problem is, I am guessing that this solves it but I may be thinking about it wrong, so for future reference make sure to clarify what the problem is more

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