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

How can I make this model not go any further?

local model = script.Parent
local available = true
function open()
	if available == true then
		for i = 0,2,0.1 do
		model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(-.25,0,0))
		wait()
		end
	end
end
script.Parent.ClickDetector.MouseClick:connect(open)

if model.Main.Position >= Vector3.new(-244.769, 139.06, 51.98) then
	print("part can't go any further!")
	local available = false
end

I'm pretty sure the whole Vector3.new thing is wrong, but I'm not sure how to make the model not go any further once the PrimaryPart is or past a certain coordinate.

1 comment

0

You will need to compare each component of the Vector3 to it's corresponding one. You can also try calculating magnitude between the two parts if you don't have to use that specific point on line 13.

1 answer

you could just put a Boolean variable to check if model is done moving like this:

local model = script.Parent
local available = true
local isdoneMoving = false

local function open() -- use local functions
    if available == true and isdoneMoving == false then
        for i = 0,2,0.1 do			model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame(CFrame.new(-.25,0,0)))
        	wait()
        end
	isdoneMoving = true
    end
end

open() -- i guess you want the function to execute automatically

script.Parent.ClickDetector.MouseClick:Connect(function() -- connect is decaperated and you forgot to put "function" because the event is connecting to the function
	if isdoneMoving == true then
		print("part can't go any further!")
  		local available = false
	end
end)

you also didnt call the function open so it wont execute, and theres probably scripting mistakes i didnt notice, so correct me. theres probably better ways then doing this, but im too clumsy right now lol

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