Serverside touch not working consistently

Basically I have 4 buttons. However, the server isn’t always picking up that they were touched. As you can see, I touch all 4, yet the touch functions only runs for 1 of them

print(button.PrimaryPart)
		--// Button has been touched
		button.PrimaryPart.Touched:Connect(function(hit)
			print(button.Name, button.PrimaryPart.CanCollide)
			if not button.PrimaryPart.CanCollide then return end -- Button is invisible, can't buy
			print("START")
			local Character = hit.Parent
			if not Character then return end
			print(1)
			local Player = Players:GetPlayerFromCharacter(Character)
			if not Player then return end 
			
			if Player ~= Owner then return end -- Make sure it's the player who owns the tycoon
			print(2)
			local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
			if not Humanoid then return end
			
			if Humanoid.Health <= 0 then return end -- Don't buy if player is dead
			
			local Cash = Player:GetAttribute("Cash")
			if not Cash then return end
			print(3)
			local Cost = button:GetAttribute("Cost")
			if Cash < Cost then return end -- Don't have enough cash
			
			if Debounce then return end
			
			Debounce = true
			
			Player:SetAttribute("Cash", Cash - Cost) -- Negate the cost from their cash
			
			local Item = button.Item.Value
			
			for _, v in pairs(Item:GetDescendants()) do
				if v:IsA("BasePart") then -- Part
					if v.Name ~= "HumanoidRootPart" then
						v.CanCollide = true
						v.Transparency = 0
					end
				elseif v:IsA("Decal") then -- Faces
					v.Transparency = 0
				end
			end	
			
			button:Destroy()
			print("TOUCHED")
		end)
1 Like

At a quick glance of your code, it looks as if you are only connecting your function to a single button rather than multiple. Try something like this:

local buttons = workspace.Buttons:GetChildren()

local function pressMe()

print("I was pressed")

end

for i, v in ipairs(buttons) do

v.Touched:Connect(pressMe)

end

I think this should resolve your issue

Sorry, I didn’t post the entire for loop causes there’s hundreds of things inside it. This function is inside a for loop, so each button has the touched function attached to it

My bad, the video just loaded. Are all the buttons using the same debounce variable? If so, I believe that could be the source of your delay?