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

I want to make a value always equal to the torso's position?

Asked by
Mystdar 352 Moderation Voter
9 years ago

He is my code (Yes, the parenting is correct)

Torso = script.Parent.Parent.Parent.Parent.Torso.Position

Torso.Changed:connect(function() -- Error, changed is not a valid member of
    script.Parent.Value = CFrame(Torso)
end)

3 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Position is a Vector3 class and not a game object, so it does not have events.

If you want something that always knows what the Torso's position is, use the Torso, and access its Position.

Ad
Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

To fix this, you simply need to get the position correctly. Your problem is that you're trying to set the CFrame of the Value, which doesn't exist. Also, you need to just use the Torso changing to find if it has moved. We can do this by using the Changed event, and finding the property that changed.


We'll fix it like so:

Torso = script.Parent.Parent.Parent.Parent.Torso

Torso.Changed:connect(function(Property) -- Error, changed is not a valid member of
    if Property=="Position" then
        script.Parent.Value = Torso.Position
    end
end)

Just a couple simple mistakes you made, that's all.


Anyways, if you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

-Dyler3

0
On line 1 you are already doing Position, so on line 4 you are doing Torso.Position.Position? Mystdar 352 — 9y
1
No, I updated it. I already caught that. Thanks for pointing it out though dyler3 1510 — 9y
0
Doesn't work, sorry Mystdar 352 — 9y
1
Where is the script located? dyler3 1510 — 9y
Log in to vote
1
Answered by 9 years ago

How about this:

local torso = script.Parent.Parent.Parent.Parent.Torso
local posVal = script.PositionValue (Vector3 value)

while true do
    wait()
    if torso.Position ~= posVal.Value then
        posVal.Value = torso.Position
    end
end

Answer this question