Needing help with making bed to levitate (Scripting Help)

Hello developers! So I am making a game and I’m a little bit stuck with script… And I want the bed to levitate.

Alright, so what I currently have is this model,


Then this is what makes up the model,
unknown
And finally, the video example of how the bed currently works,

I’ve tried looking at script, editing it a bit, my friend tried to find what’s wrong but he didn’t find what might be wrong.

In conclusion, this is the script I currently have,

local tweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)

local Point1 ={
	
	Position = Vector3.new(-29.635, 39.8, -45.991);
	Orientation = Vector3.new(0, 90, -0.2);
}

local Point2 ={

	Position = Vector3.new(-29.635, 39.6, -45.991);
	Orientation = Vector3.new(0, 90, 0.3);
}

local tween1 = tweenService:Create(script.Parent.ROOT,tweenInfo,Point1)
local tween2 = tweenService:Create(script.Parent.ROOT,tweenInfo,Point2)
while true do
	tween1:Play()
	tween1.Completed:Wait()
	tween2:Play()
	tween2.Completed:Wait()
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Apparently this is not a script-based problem, it is a model assembly problem where the constraints(e.g. weld constraints) are not attached to the root and/or are anchored. Unlike every other part of the model, the root should be anchored.

To solve this issue, weld the rest of the parts and ensure they aren’t anchored.

They are all attached to the root and aren’t anchored except for the root, but yet it’s not working.

Then it has come to my understanding that your stated problem is not clear enough. The video example only seems to show that the bed’s parts are not all levitating at once, thus assuming that there was a welding problem. What exactly is your end goal here?

The end goal is to have all parts moving with the root as opposed to being static.

I still believe that you haven’t properly secured the weld constraints to the root(might have ended elsewhere) or unanchored them(double check it anyways).

Maybe this can help you out a bit?

You can also check out:
https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame

This method could work as an alternative, but the previous method involving an anchored root with most parts welded to it is semantically the same.

The difference? Quite insignificant, remembering that one post pointed out that in long-term usage of SetPrimaryPartCFrame resulted bad precision.

Just tween the cframe of the model. It is the easiest way.

Local tween1 = tweenService:Create(script.Parent,tweenInfo,{CFrame = CFrame.new(Point1.Position, Point1.Orientation)})

I do not believe setting position respects constraints, setting CFrame does though.

Oh wait, I overlooked this. Apparently setting CFrame is better than the position as aforementioned post, explained why that only one part moved and the others didn’t.

Here is an alternative way of doing it ( I think it’s a good way )

-- Services
local RunService = game:GetService('RunService')

-- Variables
local Bed = script.Parent
local Offset = Vector3.new(0,Bed.PrimaryPart.Position.Y, 0)

-- Levitate
RunService.Heartbeat:Connect(function()
	Bed.PrimaryPart.CFrame = CFrame.new(
		Bed.PrimaryPart.Position.X,
		math.sin(tick()*2),
		Bed.PrimaryPart.Position.Z
	) + Offset
end)
1 Like

Thank you! This script actually worked with the bed.

1 Like