Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"Position is not a valid member of Model"?

hi guys

i have a game about transportation and now i am adding lifts. BUT MY SCRIPT DOESN'T WORK! it keeps erroring:

"Position is not a valid member of Model"

well, that's a stupid name for a part. but the problem is IT NORMALLY WORKS! the part is anchored and is ALWAYS there, but randomly when playing or testing that error occurs.

the part is inside a model and the model is targeted with an ObjectValue inside the script

main = script.Parent.Parent.Main
iM = script.Parent.isMoving
cM = script.Parent.canMove
iU = script.Parent.inUse
floors = script.Parent.Parent.Parent:GetChildren()	--where to look for floors
speed = 0		--current speed, changing it does nothing
maxSpeed = 4	--highest speed
tolerance = 5	--how many studs before destination the lift slows down
minSpeed = 0.4	--minimal speed when slowing down
acceleration = 0.2	--I hope I don't have to explain this?
hasStopped = false
holdPos = Vector3.new()
lastDirectionUp = false

wait(0.1)

function up()
	lastDirectionUp = true
	main.Anchored = false
	main.BodyVelocity.MaxForce = Vector3.new(0, math.huge, 0)
	main.BodyVelocity.Velocity = Vector3.new(0, speed, 0)
	iM.Value = true
end

function down()
	lastDirectionUp = false
	main.Anchored = false
	main.BodyVelocity.MaxForce = Vector3.new(0, math.huge, 0)
	main.BodyVelocity.Velocity = Vector3.new(0, -speed, 0)
	iM.Value = true
end

function stop()
	iM.Value = false
	main.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
	if hasStopped == false then
		hasStopped = true
		if lastDirectionUp == true then
			holdPos = Vector3.new(
				main.Position.X, 
				(math.ceil(main.Position.Y*10))/10, 
				main.Position.Z)
		elseif lastDirectionUp == false then
			holdPos = Vector3.new(
				main.Position.X, 
				(math.floor(main.Position.Y*10))/10, 
				main.Position.Z)
		end
	end
	if (main.Position.Y +0.05) < holdPos.Y then
		up()
	elseif (main.Position.Y -0.05) > holdPos.Y then
		down()
	else
		main.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
		speed = minSpeed
	end
end

function checkFloors()
	local canGo = true
	for i,floor in pairs(floors) do
		if floor:FindFirstChild("DoorClosed") then
			if floor.DoorClosed.Value == false then
				canGo = false
			end
		end
	end
	if canGo then script.Parent.canMove.Value = true
	else script.Parent.canMove.Value = false end
end

while wait(0.1) do
	if script.Parent.targetFloor.Value ~= nil then
		if (main.Position.Y -tolerance) > script.Parent.targetFloor.Value.Position.Position.Y
		or (main.Position.Y +tolerance) < script.Parent.targetFloor.Value.Position.Position.Y then
			speed = speed +acceleration
		else
			speed = speed -acceleration
		end
	end
	if speed < minSpeed then speed = minSpeed end
	if speed > maxSpeed then speed = maxSpeed end
	
	if cM.Value == true then
		if script.Parent.targetFloor.Value ~= nil 
		and (main.Position.Y +0.08) < script.Parent.targetFloor.Value.Position.Position.Y then
			up()
			hasStopped = false
		elseif script.Parent.targetFloor.Value ~= nil 
		and (main.Position.Y -0.08) > script.Parent.targetFloor.Value.Position.Position.Y then
			down()
			hasStopped = false
		else
			stop()
		end
	else
		stop()
	end
	
	r1 = Region3.new(
    Vector3.new(
        math.min(script.Parent.Parent.pos1.Position.X, script.Parent.Parent.pos2.Position.X),
        math.min(script.Parent.Parent.pos1.Position.Y, script.Parent.Parent.pos2.Position.Y),
        math.min(script.Parent.Parent.pos1.Position.Z, script.Parent.Parent.pos2.Position.Z)
    ),
    Vector3.new(
        math.max(script.Parent.Parent.pos1.Position.X, script.Parent.Parent.pos2.Position.X),
        math.max(script.Parent.Parent.pos1.Position.Y, script.Parent.Parent.pos2.Position.Y),
        math.max(script.Parent.Parent.pos1.Position.Z, script.Parent.Parent.pos2.Position.Z)
    )
)



plrFound = false
	
	for i,Part in pairs(game.Workspace:FindPartsInRegion3(r1,nil,math.huge)) do
		if Part.Name == "Head" then
			plrFound = true
		end
	end
	
	if plrFound == true then
		iU.Value = true
	else
		iU.Value = false
	end
	
	checkFloors()
end

sorry it's unorganized af lol (believe me, a lot of people have worse organized scripts)

2 comments

0

Can you say what line the error is on?

0

random lines

2 answers

It's probably located in a model, try checking your .Parent's and calculate it again :p

That should do it, you can't change a position of a model unless you use like the MoveTo thing :p

1 comment

0

nope, there is a part named Position inside the model, the model is a floor, and the Position part is used by the lift to know where to go

Try re-naming your part to something else.

Roblox may find trouble when trying to look for a part named that but also think you want to Position the model.

For instance:

game.Workspace.Model.Position

Roblox will presume you want to move the model, and therefore print "Position is not a valid member of Model"

On the other hand, if you specify it with a different name such as "PositionPart" like so:

game.Workspace.Model.PositionPart

It will go into the Model's children and locate the part you are looking for since PositionPart is not a Vector value.

Hope this helps!

1 comment

0

thx, will try this

This discussion is preserved as it was. New answers, comments, and votes are closed.