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

Help with events?

Asked by 10 years ago

I was trying to update the position of the players head every time the position is changed but I got an error:

Changed is not a valid member

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
-----------------------------------------------------
        Head = Character:FindFirstChild("Head")
        Head.Position.Changed:connect(function()
            local Ray = Ray.new(Head.Position,
            Head.CFrame.lookVector.unit*1000)
            local Hit = Workspace:FindPartOnRay(Ray)
                if not Hit then
                    print("Nope")
                else
                    print(Hit)
            end
        end)
    end)
end)
0
You cannot use the Changed event on the Position property because it consists of 3 other properties - X, Y, and Z. You mayt be able to use the Changed event on a specific scale but not as specifying them all. Goulstem 8144 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

You're trying to call the Changed event on a property, which will not work, thus stating Changed is not a valid member of the property. The event is located in the object, the actual head part.

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        Head = Character:WaitForChild("Head") --In case the head isn't found when you spawn.
        Head.Changed:connect(function(prop) --We call the Changed event on the head part.
            if prop == "Position" then --The check to see if the property that changed is the position property.
                local Ray = Ray.new(Head.Position,
                Head.CFrame.lookVector.unit*1000)
                local Hit = Workspace:FindPartOnRay(Ray)
                if not Hit then
                    print("Nope")
                else
                    print(Hit)
                end
            end
        end)
    end)
end)
1
Note that Physics changes DO NOT fire the Changed event (e.g., normal motion will not triggered a "Changed" for Position) BlueTaslem 18071 — 10y
1
@Blue Thanks for the heads up. Spongocardo 1991 — 10y
Ad

Answer this question