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

[SOLVED] Attempting to switch a part's position but it indicates "attempt to call a nil value"?

Asked by 2 years ago
Edited by Xapelize 2 years ago

SOLVED: I used Vector3.New when it should've been Vector3.new

So it's a pathfinding script with a random chance (though for testing purposes it's meant to happen 100% of the time in the script below) for one of the pathfinding parts to change positions. However, it indicates that I attempted to call a nil value.

The important part in my script is this:

local chance = math.random(1,1)
            if chance == 1 then
                script.Parent.Parent.Path:FindFirstChild("5").Position = Vector3.New(1.473, 0.5, 48.737)

Though if anyone wants here's the full script:

local WalkPoints = script.Parent.Parent.Path
local waitPoint = WalkPoints:WaitForChild("1")
local points = WalkPoints:GetChildren()

while true do
    for i=1,#points do
        repeat
            script.Parent.Humanoid:MoveTo(WalkPoints[i].Position)
            wait(.5)
            local chance = math.random(1,1)
            if chance == 1 then
                script.Parent.Parent.Path:FindFirstChild("5").Position = Vector3.New(1.473, 0.5, 48.737)
            end
        until (script.Parent.Torso.Position - WalkPoints[i].Position).magnitude <= 4
        script.Parent.Torso.Anchored = true
    end
end

Answer this question