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

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

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

✓ Accepted answer

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)

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