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

How can I make this model not go any further?

Asked by
Stravan 18
6 years ago
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.

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. xPolarium 1388 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

Ad

Answer this question