#Change script so model moves instead of part

1 messages · Page 1 of 1 (latest)

reef kiln
#

Hello, I have a working door script that will allow me to move a single object like a part/union, but I want to change this so that I can move a door model instead. I thought that if I specified the model door like I did with a union, it would work the same. The best I've gotten was moving the primary part of the model, which just left everything else behind. I'm not sure how to specify the model and get all parts of the model to move.

The main error I am getting is

CFrame is not a valid member of Model "Workspace.Sliding Single Door.Door" - Server - SlidingSingleDoorScript:9

My code is:

open = false

local door = script.Parent.Parent.Parent.Door
local opensound = script.Parent.OpenSound
local closesound = script.Parent.CloseSound
local prompt = script.Parent

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local DoorOpen = {CFrame = door.CFrame * CFrame.new(-11,0,0)}
local DoorClose = {CFrame = door.CFrame}

local Open = TweenService:Create(door,tweenInfo,DoorOpen)
local Close = TweenService:Create(door,tweenInfo,DoorClose)

prompt.Triggered:Connect(function()
    if open == false then
        open = true
        opensound:Play()
        Open:Play()
        wait(2)
    else
        closesound:Play()
        Close:Play()
        wait(2)
        open = false
    end
end)

BTW the prompt is a proximity prompt, which the script is inserted, everything else worked before, it's just changing the union doors to model doors is what's causing the issue.
Also everything in the model is properly welded together, if that is something necessary.

I really appreciate the help and advice, I am new to scripting :)

knotty hinge
#

pivot to

#

it moves the model with everything inside

#

and primary part position

#

will be the designated cframe

reef kiln
#

so I have an update,
using Pivots did move the door, but it moved the door on game join rather than on prompt trigger, prompt trigger did nothing actually.

I got the error: TweenService:Create no property named 'CFrame' for object 'Door'

I am using TweenService to animate the door moving. I also plan to later tweak the script to have the door automatically close rather than having to trigger the prompt again, but right now I want to get the door working.

here's my new script, is there a different way I could write it so the prompt.Trigger actually causes the door to open/close?

open = false

local door = script.Parent.Parent.Parent.Door
local opensound = script.Parent.OpenSound
local closesound = script.Parent.CloseSound
local prompt = script.Parent

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local doorPiv = door:GetPivot()
local DoorOpen = {CFrame = door:PivotTo(doorPiv * CFrame.new(-6,0,0))}
local DoorClose = {CFrame = doorPiv}

local Open = TweenService:Create(door,tweenInfo,DoorOpen)
local Close = TweenService:Create(door,tweenInfo,DoorClose)

prompt.Triggered:Connect(function()
    if open == false then
        open = true
        opensound:Play()
        Open:Play()
        wait(2)
    else
        closesound:Play()
        Close:Play()
        wait(2)
        open = false
    end
end)
royal bloomBOT
#

studio** You are now Level 2! **studio

reef kiln
#

Alright, I made a modification that allows me to control the door with the prompt, but now it moves instantly and without animation, basically like if TweenService isn't there

open = false

local door = script.Parent.Parent.Parent.Door
local opensound = script.Parent.OpenSound
local closesound = script.Parent.CloseSound
local prompt = script.Parent

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local doorPiv = door:GetPivot()

prompt.Triggered:Connect(function()
    if open == false then
        open = true
        opensound:Play()
        DoorOpen = {CFrame = door:PivotTo(doorPiv * CFrame.new(-6,0,0))}
        TweenService:Create(door,tweenInfo,DoorOpen):Play()
        wait(2)
    else
        closesound:Play()
        DoorClose = {CFrame =door:PivotTo(doorPiv * CFrame.new(0,0,0))}
        TweenService:Create(door,tweenInfo,DoorClose):Play()
        wait(2)
        open = false
    end
end)
reef kiln
#

I finally got it to do what I wanted, I focused TweenService on the primary part CFrame instead of pivoting the whole model, and I unanchored all the other parts (not the primary part)