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
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
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.
“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.