Position is not a valid member of Model

Hello there,

I am having trouble getting my animated NPCs to work. Basically what they do is, you walk up to the shop owner, and a textlabel appears, you press “F” and a shop pops up. But for some reason they aren’t working anymore. Does anyone know how to fix this?

Error in the Console

image

Code
local position1 = workspace.NPCs.Owner.Sven.Torso
repeat wait() until game.Players.LocalPlayer.Character
while true do
    local position2 = game.Players.LocalPlayer.Character.Position
    local distance = (position1 - position2).magnitude
    if distance < 4 then
        script.Parent.Parent.PlayerGui.UserInterface.Thing.Visible=true
    else
        script.Parent.Parent.PlayerGui.UserInterface.Thing.Visible=false
    end
    wait(.1)
end
9 Likes

I believe position1 is referring to the Torso itself, and not it’s position.

1 Like

The error is coming from position2, on line 4.

Models have no position. Use Character.HumanoidRootPart.Position or similar, or use Character.PrimaryPart.CFrame. The primary part is not guarenteed for to be set for any model though (characters it should be). I usually index the root part by name.

11 Likes

I tried your solution and got another error

image

Did I need to do something else as well?

Did the line change at all, because by that error you tried.

game.Character -- this doesn't exist
1 Like

image

“Character” is the Model. It’s not a part with a position property.
You will also want to make sure the character exists each loop otherwise it will break when players die/reset.

2 Likes

Thank you @Darkmist101 and @Dev_Ryan. This fixed my issue.