Force in the same direction as the door

So I needed help on making a door that “breaks” when you open it like this:


But when I put it in a different direction, it looks weird.

How can I achieve this? This is my script.

local door = script.Parent
local debounce = false

local function getPlayerFromCharacter(character)
	for _, player in game:GetService("Players"):GetPlayers() do
		if player.Character == character then
			return player
		end
	end
end

door.Touched:Connect(function(player)
	if player.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			player.Parent.HumanoidRootPart.CFrame = door.Parent.TeleportPart.CFrame
			player.Parent.HumanoidRootPart.CanCollide = false
			player.Parent.Humanoid.WalkSpeed = 0
			player.Parent.Humanoid.AutoRotate = false
			player.Parent.Humanoid.JumpPower = 0
			door.CollisionGroup = "Door"
			debounce = true
			door.Break:Play()
			door.Anchored = false
			door.AssemblyLinearVelocity = Vector3.new(0,0,-50)
			task.wait(1)
			game.ReplicatedStorage.Events.AAAHHHHH:FireClient(getPlayerFromCharacter(player.Parent))
		end
	end
end)

Looks like you are using ToWorldSpace for your CFraming instead of ToObjectSpace.

Have a read through the links above.
Also a quick search using both of those terms gets you posts like this one:
ToWorldSpace - ToObjectSpace

I got an error in my script

Change that line to the doors cframe * CFrame.new(0,0,50) (or -50)

You are doing it relative to the world, and not the object.

I got an error saying Vector3 expected, got CFrame. This is what I changed, door.AssemblyLinearVelocity = door.CFrame * CFrame.new(0,0,-50)

door.AssemblyLinearVelocity = door.Position * Vector3.new(0,0,-50)
then change it to Vector3

I don’t think that solves the problem well

try add the value instead of multiplying

What do you mean by value?

change this

to

door.AssemblyLinearVelocity = door.Position + Vector3.new(0,0,-50) -- you might want to change here to your liking

The same result but less farther

exactly why I say

if it go way too far then just lower the number

Well, lowering the number works, but the door goes sideways and I want it to go to the direction the door is facing. This is what I’m talking about.

door.AssemblyLinearVelocity = door.CFrame.LookVector * 50

Change the multiplyer to what ever value you see fit

1 Like

Oh, I didn’t know know there was a LookVector variable. Thanks for the tip!

1 Like

I didn’t notice that you were using AssemblyLinearVelocity, but the documentation states in cases like this you should probably use a VectorForce or ApplyImpulse for something like this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.