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

How do I fix my BodyPostion script on a sliding door?

Asked by 4 years ago

I tried making a script using BodyPostion which selects all the parts of a door and moves them to a different position to make it a sliding door. However, when it tries setting the BodyPostion it doesn't work and nothing happens.

local door = script.Parent.Parent.Model:GetChildren()

script.Parent.ClickDetector.MouseClick:Connect(function(Onclick)
    for _,part in pairs(door) do
        local yPosition = part.Position.Y
        local zPosition = part.Position.Z
        part.CanCollide = false
        part.BodyPosition.Position = Vector3.new(-24.325,yPosition,zPosition)
    end
end)

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
4 years ago

For stuff like a sliding door it is best to use TweenService.

local TweenService = game:GetService("TweenService")
local door = script.Parent.Parent.Model:GetChildren()
local TweeningInformation = TweenInfo.new(3) --door will be opening for 3 seconds

script.Parent.ClickDetector.MouseClick:Connect(function(Onclick)
    for _,part in pairs(door) do
        local yPosition = part.Position.Y
        local zPosition = part.Position.Z
    local target = {Position = Vector3.new(-24.325,yPosition,zPosition)}
        part.CanCollide = false 
    local tween = TweenService:Create(part,TweeningInformation,target)
    tween:Play()
    end
end)
Ad

Answer this question