Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Check what touched a part?

I'm writing a tycoon, and I'm having some issues with an owner script. The script works fine until I make it check if a humanoid touches it, how can I solve this please?

script.Parent.Touched:connect(function(z) -- this is the original working code
	if script.Parent.Parent.Name == "UnOwnedTycoon" then
		
		script.Parent.Parent.Name = z.Parent.Name .. "'s tycoon"
		print(z)
		print(z.Parent)

		
	end
	owner = z.Parent.Name
end)
script.Parent.Touched:connect(function(z) -- And this is the broken checking code
	if script.Parent.Parent.Name == "UnOwnedTycoon" and z.Parent.PrimaryPart == Head then
		
		script.Parent.Parent.Name = z.Parent.Name .. "'s tycoon"
		print(z)
		print(z.Parent)

		
	end
	owner = z.Parent.Name
end)

1 answer

You should change the and,

script.Parent.Touched:connect(function(z) -- And this is the broken checking code
    if script.Parent.Parent.Name == "UnOwnedTycoon" and z.Parent:FindFirstChild("Humanoid") then-- instead of Head, a lot easier and should work.

        script.Parent.Parent.Name = z.Parent.Name .. "'s tycoon"
        print(z)
        print(z.Parent)


    end
    owner = z.Parent.Name
end)

If this worked please accept the answer, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.