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

Why won't my moving door move the wedges and unions? Only the parts.

Asked by 2 years ago

https://gyazo.com/c4915818073c2d75c318005130b88e99 There is a video of the door, seems to be ignoring everything but parts.

I tried putting "Wedge" and "UnionOperation" with "Part" in classnames but that didn't help

function Activate()
    if script.Parent.Parent.Active.Value == true and script.Parent.Parent.Power.Value == true then
        wait(2)
        local g = script.Parent:GetChildren()
        for b = 1, 40 do
            for i = 1, # g do
                if g[i].className == "Part" then
                    g[i].CFrame = g[i].CFrame + Vector3.new(0, 0, .05)
                end
            end
            wait(.025)
        end
        wait(2)
        for b = 1, 185 do
            for i = 1, # g do
                if g[i].className == "Part" then
                    g[i].CFrame = g[i].CFrame + Vector3.new(0.1, 0, 0)
                end
            end
            wait(.05)
        end
        script.Parent.Parent.Valid.Value = true
    elseif script.Parent.Parent.Active.Value == false then
        wait(2)
        local g = script.Parent:GetChildren()
        for b = 1, 185 do
            for i = 1, # g do
                if g[i].className == "Part" then
                    g[i].CFrame = g[i].CFrame + Vector3.new(-0.1, 0, 0)
                end
            end
            wait(.05)
        end
        wait(2)
        for b = 1, 40 do
            for i = 1, # g do
                if g[i].className == "Part" then
                    g[i].CFrame = g[i].CFrame + Vector3.new(0, 0, -.05)
                end
            end
            wait(.025)
        end
        script.Parent.Parent.Valid.Value = true
    end
end

script.Parent.Parent.Active.Changed:connect(Activate)

1 answer

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

In this case, I feel like TweenService would result in a smooth, good-performance finish with much less lines of codes (Can tell you how to do that if you want).

But in this code, where ever it says:

if g[i].className == "Part" then

Try using this instead:

if g[i]:IsA("BasePart") then

BasePart refers to every kind of part - wedges, unions, spawnlocations, and etc.


First, you have to set a primary part in the properties of the model you are tweening. To do this create part, and scale it to the size of the model (try your best with this process using the blue selection box/outline roblox gives when you hover over the model), Set the transparency of this part to 1 (invisble), set the cancollide to false. Then, name this part "Primary" and parent it to the model. Then, you can select this part as the PrimaryPart of the model you're tweening.

Make sure to unanchor all the parts in the model.

Then only anchor the PrimaryPart.

Second, you have to create welds between the primary part and all the other parts of that model. Personally, I use this code for welding.

local model = workspace["Model"] -- Replace the value of this variable with the location of the model in the workspace

for i,v in pairs(model:GetDescendants()) do
    if v:IsA("BasePart") then
        local Weld = Instance.new("WeldConstraint")
        Weld.Parent = v
        Weld.Part0 = v
        Weld.Part1 = model.PrimaryPart
    end
end

Like the comments say, replace the model variable with the location of the model you're tweening in the workspace.

Then, run this code in the command bar at the bottom of roblox studio - to activate command bar if it's not there, go to the view tab at the top and click on command bar.

After that, there should be WeldConstraints through all your parts attaching to the primaryPart.

All you have to do from there on is write the Tween Script. Insert a script into the model and type the following:

local TweenService = game:GetService("TweenService")

local Model = script.Parent -- Your model
local PrimaryPart = Model.PrimaryPart -- the PrimaryPart is the part you assigned as PrimaryPart earlier
local ActiveValue = Model.Active -- Change to location of active value
local EventDebounce = false

-- You can change these properties to whatever you would like (I would only change time based on how long you want the door animation to be)
local ModelTweenInfo = TweenInfo.new(
    3, -- The time it takes to complete the tween 
    Enum.EasingStyle.Linear, 
    Enum.EasingDirection.In, 
    0, -- Number of times you want to repeat the tween
    false, -- Bool reverses
    0 -- Delay between each tween
)

local OpenTween = TweenService:Create(PrimaryPart, ModelTweenInfo, {CFrame = PrimaryPart.CFrame * CFrame.new(0, 0, 10)}) -- Mess around with the distance and axis you want the model to travel. 
local CloseTween = TweenService:Create(PrimaryPart, ModelTweenInfo, {CFrame = PrimaryPart.CFrame * CFrame.new(0, 0, 0)})


ActiveValue.Changed:Connect(function()
    if ActiveValue.Value == true then
        OpenTween:Play()
    else
        CloseTween:Play()
    end
end)

Without the comments and open formatting the code should appear much shorter.

local TweenService = game:GetService("TweenService")

local Model = script.Parent
local PrimaryPart = Model.PrimaryPart
local ActiveValue = Model.Active 
local EventDebounce = false

local ModelTweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)

local OpenTween = TweenService:Create(PrimaryPart, ModelTweenInfo, {CFrame = PrimaryPart.CFrame * CFrame.new(0, 0, 10)}) -- Mess around with the distance and axis you want the model to travel. 
local CloseTween = TweenService:Create(PrimaryPart, ModelTweenInfo, {CFrame = PrimaryPart.CFrame * CFrame.new(0, 0, 0)})

ActiveValue.Changed:Connect(function()
    if ActiveValue.Value == true then
        OpenTween:Play()
    else
        CloseTween:Play()
    end
end)

I tried to make it as adjustible to your model as possible - if you give me a screenshot of how your model is layed out, I may be able to specify the code more. But, this is the final result should be smooth and very adaptable.

0
Hello, yea please tell me how to do it with Tween. SoCloseToBanan -7 — 2y
0
And thank you, it worked! SoCloseToBanan -7 — 2y
0
Alright, its a bit tedious to explain, so I will try my best. SprinkledFruit101 135 — 2y
0
Here you go - let me know if you run into any issues! SprinkledFruit101 135 — 2y
Ad

Answer this question