Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Check what touched a part?

Asked by 8 years ago

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

Log in to vote
0
Answered by
xuefei123 214 Moderation Voter
8 years ago

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!

Ad

Answer this question