Touched event doesnt work

Hey,

nothing is printing, but idk why.

local Part = script.Parent
local Debounce = true
Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if Debounce == true then
			Debounce = false
			warn("Touched works")
			local Tycoons = game.Workspace["Zednov's Tycoon Kit"].Tycoons
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local PlayerTycoon = player.Team
			for _,child in pairs(Tycoons:GetChildren()) do
				if child.Owner.Value == player.Name then
					warn("Tycoon found")
					local PO = child.PurchasedObjects
					if PO:FindFirstChild("Walls") then
						warn("Walls found")
						local Walls = PO.Walls.Colored:GetChildren()
						for i,v in pairs(Walls) do
							v.BrickColor = BrickColor.new(0.9,0.6,0.2)
						end
						break
					else
						warn("Walls not found")
						break
					end
				end
				
			end
			wait(1)
			Debounce = true
		end
		end
end)

Is your Parts CanCollide set to false? Otherwise your code should warn as normal.

1 Like

Nvm. I had canTouch toggled off, now it prints “Touched works” but nothing else. Any idea?

If you didn’t get an error then the Owner instances value does not match the players name.

This isnt possible. There are 4 childs and one of it has the same owner value as the player name

What type of value is owner? If it is a StringValue, then this should work. If it is an ObjectValue, consider doing Value == object instead.

Its a object value. But wdym by == object

Do this instead:
if child.Owner.Value == player then (This being that the owner value is usually set to the player)

Tysm, that actually works :slight_smile: Thank you