Click multiplier

Hello! I want to have a script that can multiply the amount of (in my case) codes you get from clicking your mouse. I have made 4 different models that gets added to your player backpack when you buy them, and they all have different cpc (codes per click) values. I need a script to get that value and add it to the amount of clicks you normally get. However there are some errors. my code and some screenshots are listed here:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local starterRebirthAmount = 5000
local player = game:GetService("Players").LocalPlayer
local cooldown = .5

replicatedStorage.Remotes.GiveMoney.OnServerEvent:Connect(function(player,item)
	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	local debounce = remoteData[player.Name].Debounce
	local multi = player:WaitForChild("Backpack"):FindFirstChildWhichIsA("Tool").cpc.Value --problem here
	print("This works")
	if not debounce.Value then
		
		debounce.Value = true
		
		player.leaderstats.Codes.Value = player.leaderstats.Codes.Value + 1 * (player.leaderstats.Rebirths.Value + 1) * multi
		
		wait(cooldown)
		
		debounce.Value = false
		
	end
	
end)

I have tried to search it up on youtube, tried fixing the code myself by doing this

	local cpc = game:GetService("ServerStorage").PlayerTools.First_Pc.cpc
	local multi = player:WaitForChild("Backpack"):FindFirstChild().cpc.Value
	print("This works")

But that gives this error message:
Screenshot_825

And I tried searching it up but I couldn’t find anything. I would be really happy if someone helps me out here!

when you’re clicking, i assume you’re holding the tool, thus you need to be searching in the character, not the backpack.

The 2nd option error is there because you didn’t pass the name argument in the :FindFirstChild() thus it doesn’t know what to find

Whay do you mean with the first option? Do I need to change Backpack to Character?

Yes, that’s what I meant, assuming the GiveMoney Remote is fired when you click at least.

the script I have now is:

replicatedStorage.Remotes.GiveMoney.OnServerEvent:Connect(function(item,player1)	
        if not remoteData:FindFirstChild(player1.Name) then return "NoFolder" end
	local debounce = remoteData[player1.Name].Debounce
	local player = game.Players:GetPlayerFromCharacter(player1)
	if player then
		for i, tools in pairs(player.Backpack:GetChildren()) do
	local data = {}
	local cpc = game.ServerStorage.ToolModels[tools.Name].cpc.Value
	
	table.insert(data,1,cpc)
			print("This works")

But now I get an error message saying

Line #9 is

if not remoteData:FindFirstChild(player1.Name) then return "NoFolder" end 

I found out that I can’t use local player in a server script :sweat_smile:. But how would I do it in another way?

I have made some changes in the code and deleted some things that didn’t matter/didn’t work. Now the code is this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local starterRebirthAmount = 5000
local cooldown = .5
local players = game:GetService("Players").LocalPlayer
	
replicatedStorage.Remotes.GiveMoney.OnServerEvent:Connect(function(Player,item)
	if not remoteData:FindFirstChild(Player.Name) then return "NoFolder" end				
	
	local debounce = remoteData[Player.Name].Debounce

	local player = game.Players:GetPlayerFromCharacter(Player)
	
	for i, tools in pairs(Player.Backpack:GetChildren()) do
		print("This works")
	local data = {}
	local cpc = game.ServerStorage.PlayerTools[tools.Name].cpc.Value

But now it does nothing when I click. No error message and it doesn’t print “This works” either

still does nothing when I delete that

It stops after

for i, tools in pairs(Player.Backpack:GetChildren()) do

this is the intire code now:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local starterRebirthAmount = 5000
local cooldown = .5
	
replicatedStorage.Remotes.GiveMoney.OnServerEvent:Connect(function(Player,item)
	if not remoteData:FindFirstChild(Player.Name) then return "NoFolder" end				
	
	local debounce = remoteData[Player.Name].Debounce


	for i, tools in pairs(Player.Backpack:GetChildren()) do
		print("This works")
	local data = {}
	local cpc = game.ServerStorage.PlayerTools[tools.Name].cpc.Value
	
	table.insert(data,1,cpc)
			print("This works")
			if not debounce.Value then

				debounce.Value = true

				Player.leaderstats.Codes.Value = Player.leaderstats.Codes.Value + 1 * (Player.leaderstats.Rebirths.Value + 1) * (data[1])

				wait(cooldown)

				debounce.Value = false

			end
		end
	end)

I removed that line but it still does nothing

it prints up to

	local debounce = remoteData[Player.Name].Debounce

sure thing

I’ll try to search for the problem somewhere else, I changed the Player.Backpack:GetChildren to game.ServerStorage.PlayerTools:GetChildren()). That seemed to work and I got codes but there is still another problem, now it says: timmiegamer123 is not a valid member of Folder "ServerStorage.PlayerTools.timmiegamer123.

The new code is:

replicatedStorage.Remotes.GiveMoney.OnServerEvent:Connect(function(Player,item)
	if not remoteData:FindFirstChild(Player.Name) then return "NoFolder" end				
	
	local debounce = remoteData[Player.Name].Debounce
	print("This works")

	for i, tools in pairs(game.ServerStorage.PlayerTools:GetChildren()) do

	local data = {}
	local cpc = game.ServerStorage.PlayerTools[Player.Name][tools.Name].cpc.Value
	
	table.insert(data,1,cpc)
			print("This works")
			if not debounce.Value then

				debounce.Value = true

				Player.leaderstats.Codes.Value = Player.leaderstats.Codes.Value + 1 * (Player.leaderstats.Rebirths.Value + 1) * (data[1])

				wait(cooldown)

				debounce.Value = false

			end
		end
	end)

oh hey that works, thank you so much!!! sorry I was making the reply and didn’t see you edited it