I'm coding a Clicker Game plugin, and it isn't going very well

So, I’m trying to script an image-changing Button for my clicker game plugin. However, it isn’t working. Can somebody help?


I will test every script, and make sure that it works myself. The problem I’m having is that the detection for table.find(Rewards, 7) does absolutely nothing, and it’s always stuck at the “else” part of the statement no matter what I do.

ids could be invalid
Decal ID and Image ID is not the same
Image ID is the one you need

^ It’s all valid, I tested it and it only prints YTE

It would help to understand the structure of Rewards. As the issue presents itself, I’m assuming that 7 cannot be found in Rewards though I don’t know what Rewards looks like on runtime + there isn’t a guarantee that 7 is in Rewards with the amount of code we can see.

I mean the only thing I can think of is a type issue where you set "7" into the table and expect it to get found when searching for 7 (non-string).

Don’t believe that you are right that it “doesn’t work no matter what”, walk through your code out loud, or tell a friend how it works.

As a beginner, you might often think that your code should work exactly as you think it should. It’s not magically failing, you just need to put more effort and put aside that “no matter what” it fails. Okay, let’s give you an example strategy here:

  1. “I’ll check where I am adding numbers to Rewards. Maybe I am not adding 7 for some reason.”
  2. check script A, script B, …

Okay, @trigophi makes a good point, what if you put “7” in the table but you printed it and thought it was really the number 7? Bad type.

Don’t start re-running the script a million times, the 7 isn’t just there magically, you don’t just have code that contradicts itself. There’s a reason it failed. Be skeptical because you have a lead.

And in addition, you put too little code. You could have an invisible mistake somewhere else and none of us would be able to tell. We can’t solve your problem if the problem isn’t even in the code you took a screenshot of. What are you doing to Rewards?

1 Like

Is rewards an array of numbers? Because if it isn’t even one of those, your finding line won’t work.

If you don’t know the difference between arrays and dictionaries

Arrays:

local myArray = {“Apple”, “Banana”, “Mango”}
local appleindex= table.find(myArray, “Apple”)

Dictionaries:

local myDictionary = {
   [“Apple”] = 1,
   [“Banana] = 4,
   [“Mango”] = 3
}
local apples = myDictionary[“Apple”]
local Service = plugin:CreateToolbar("Clicker")
local StartupIcon = Service:CreateButton(1, "Open A-60 Clicker", "rbxassetid://11710144220", "Clicker")
local UI = nil
local ID = 0
local ID2 = "Goober"
local Cash = 0
local Button = nil
local Images1 = {15695685896, 11710144220, 15695692724, 15695696042, 15695700010}
local Images2 = {12650043114, 12650020367, 12650016607, 12650033855, 12650027980}
local Rewards = {}
local ImageChangePause = false
local RewardCount = 14
local ClickMultiplier = 1
local Rebirths = 0
local WaitsEnded = {}
local AutoclickerDelay = false
local Display = nil
local function CreateUpgrade(UpgradeUI, Reward, Cost, Label)
	local UI = Instance.new("TextButton")
	UI.Parent = UpgradeUI
	UI.ZIndex = 6
	UI.Text = Label .. " - $" .. Cost
	UI.TextScaled = true
	UI.Size = UDim2.fromScale(0.9, 1 / RewardCount)
	UI.Position = UDim2.fromScale(0, (Reward - 1) / RewardCount)
	UI.MouseButton1Click:Connect(function()
		if Cash >= Cost and not table.find(Rewards, Reward) then
			Cash -= Cost
			table.insert(Rewards, Reward)
			UI.BackgroundColor3 = Color3.fromRGB(86, 86, 86)
			UI.Text = Label .. " - Sold Out"
			Display.Text = "$" .. Cash
		end
	end)
end
StartupIcon.Click:Connect(function()
	if UI then
		UI:Destroy()
	end
	ID += 1
	UI = plugin:CreateDockWidgetPluginGui(ID2 .. "Clicker" .. ID, DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float))
	UI.Enabled = true
	local Frame = Instance.new("Frame", UI)
	Frame.BackgroundColor3 = Color3.fromRGB(255, 106, 0)
	Frame.Size = UDim2.fromScale(1, 1)
	local Upgrades = Instance.new("ScrollingFrame", Frame)
	Upgrades.ZIndex = 5
	Upgrades.Size = UDim2.fromScale(0.3, 1)
	Upgrades.Position = UDim2.fromScale(0.7, 0)
	Display = Instance.new("TextLabel", Frame)
	Display.Text = "$" .. 0
	Display.ZIndex = 5
	Display.AnchorPoint = Vector2.new(0.5, 0.5)
	Display.Size = UDim2.fromOffset(300, 100)
	Display.Position = UDim2.fromScale(0.079, 0.042)
	Display.BackgroundTransparency = 1
	Button = Instance.new("ImageButton", Frame)
	Button.Size = UDim2.fromOffset(200, 200)
	Button.AnchorPoint = Vector2.new(0.5, 0.5)
	Button.Position = UDim2.fromScale(0.5, 0.5)
	Button.BackgroundTransparency = 1
	Button.MouseButton1Click:Connect(function()
		if table.find(Rewards, 4) then
			if table.find(Rewards, 5) then
				if table.find(Rewards, 6) then
					if table.find(Rewards, 12) then
						if table.find(Rewards, 13) then
							if table.find(Rewards, 14) then
								ClickMultiplier = 7
							else
								ClickMultiplier = 6
							end
						else
							ClickMultiplier = 5
						end
					else
						ClickMultiplier = 4
					end
				else
					ClickMultiplier = 3
				end
			else
				ClickMultiplier = 2
			end
		else
			ClickMultiplier = 1
		end
		Cash += (ClickMultiplier * 2) + Rebirths - 1
		Display.Text = "$" .. Cash
	end)
	CreateUpgrade(Upgrades, 1, 40, "Autoclicker 1", Display)
	CreateUpgrade(Upgrades, 2, 60, "Autoclicker 2", Display)
	CreateUpgrade(Upgrades, 3, 80, "Autoclicker 3", Display)
	CreateUpgrade(Upgrades, 4, 100, "Click multiplier 1", Display)
	CreateUpgrade(Upgrades, 5, 300, "Click multiplier 2", Display)
	CreateUpgrade(Upgrades, 6, 600, "Click multiplier 3", Display)
	CreateUpgrade(Upgrades, 7, 3, "A-200", Display)
	game["Run Service"].Heartbeat:Connect(function()
		if table.find(Rewards, 7) and not table.find(WaitsEnded, 7) then
			table.insert(WaitsEnded, 7)
			CreateUpgrade(Upgrades, 8, 40000, "Rebirth", Display)
			CreateUpgrade(Upgrades, 9, 4000, "Autoclicker 4", Display)
			CreateUpgrade(Upgrades, 10, 6000, "Autoclicker 5", Display)
			CreateUpgrade(Upgrades, 11, 8000, "Autoclicker 6", Display)
			CreateUpgrade(Upgrades, 12, 6000, "Click multiplier 4", Display)
			CreateUpgrade(Upgrades, 13, 8000, "Click multiplier 5", Display)
			CreateUpgrade(Upgrades, 14, 10000, "Click multiplier 6", Display)
		end
		if table.find(Rewards, 7) and not table.find(WaitsEnded, 8) then
			table.insert(WaitsEnded, 8)
			Rebirths += 1
			Cash = 0
			Rewards = {}
			WaitsEnded = {}
			ClickMultiplier = 1
		end
	end)
end)
game["Run Service"].Heartbeat:Connect(function()
	if Display and table.find(Rewards, 1) and AutoclickerDelay == false then
		AutoclickerDelay = true
		if table.find(Rewards, 2) then
			if table.find(Rewards, 3) then
				if table.find(Rewards, 9) then
					if table.find(Rewards, 10) then
						if table.find(Rewards, 11) then
							task.wait(1 / 5)
						end
					else
						task.wait(1 / 4)
					end
				else
					task.wait(1 / 3)
				end
			else
				task.wait(1 / 2)
			end
		else
			task.wait(1)
		end
		Cash += math.abs(math.ceil(ClickMultiplier / 2))
		Display.Text = "$" .. Cash
		AutoclickerDelay = false
	end
	
	
	
	if Button and ImageChangePause == false then
		ImageChangePause = true
		if table.find(Rewards, 7) then
			print('YTRY')
			Button.Image = "rbxassetid://" .. Images2[math.random(1, #Images2)]
			task.wait(0.25)
		else
			print('YTE')
			Button.Image = "rbxassetid://" .. Images1[math.random(1, #Images1)]
			task.wait(1)
		end
		ImageChangePause = false
	end
end)