Collector giving too much

So sometimes in my game which is the dropper simulator it sometimes gives the player the int limit for some reason and i do not want it to do that.

The only things that Gives the player cash is just the collector which just gives the player cash over the block attributes heres the collector script.

local players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
	
	
	if hit:GetAttribute("CashToGive") then
	local plot = script.Parent.Parent.Parent.Parent
	if not plot then warn('No Plot') return end
	
	hit:Destroy()
	
		local PlotUSERID = script.Parent.Parent.Parent.Parent:FindFirstChild("UserID").Value
	local player =	players:GetPlayerByUserId(PlotUSERID)
		player.leaderstats.Cash.Value += hit:GetAttribute('CashToGive')
		
		if not PlotUSERID then return end
		
		
	end
	
	
end)

I think its because its exausted for some reason but the dropper script is here aswell


local Block = game:GetService("ServerStorage"):WaitForChild("Blocks").DarkBlock
while task.wait(1) do
	local newpart = Block:Clone()
	newpart.CFrame = script.Parent.CFrame - Vector3.new(0,2,0)
	newpart:SetAttribute("CashToGive",script.Parent.Parent:GetAttribute("CPS"))
	newpart.Parent = script.Parent.Parent.DropperParts
	
end
1 Like

The touch is probably firing many many times. Depending on what you want to do you will need to limit the touch event to fire only once or the amount of times u desire. Debounce or cooldown period or disconnect.

Apply a tag to the dropper item, then when you are doing your validation checks and they have sai tag, remove it so its no longer used and then remove said item.

This should also prevent other objects from getting mixed as well as its only searching for a specific group or objects. In which case you could also assign a seperate CollisionGroup that is only collidable with the collector to avoid those unessecary touch events. (Note: this will depend if you have that setting enabled)