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)
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!