How do i get both of the baseparts inside the model?

code:
      local parent = script.Parent:GetChildren()
    for i = 1,#parent do
    if parent[i]:IsA("BasePart") then
while true do
	wait(0.1)
	v = parent[i]
	for i = 1, 5 do
		wait(0.1)
		v.Position = v.Position + Vector3.new(0,i/40.0)
	end
	for i = 4, 1, -1 do
		wait(0.1)
		v.Position = v.Position + Vector3.new(0,i/40.0)
	end
	wait(0.1)
	for i = 1, 5 do
		wait(0.1)
		v.Position = v.Position + Vector3.new(0,i/40.0)
	end
	for i = 4, 1, -1 do
		wait(0.1)
		v.Position = v.Position + Vector3.new(0,i/40.0)
	end
	parent[i] = v
end                                    
      end
   end

so i want it so that i get both of the baseparts, to make them both float, but it doesn’t work :confused:

Another problem is that its not going down, just goes up: example

2 Likes

its very hard to visualize what youre trying to do exactly, please provide a picture of the part hirarchy, and of the model in question if possible

1 Like

If what you meant is, getting all BasePart(s) inside a model and binding that looped float function to it, then,

local model = script.Parent
for i,v in pairs(model:GetDescendants())do
     if v:IsA'BasePart' then
          bindfloat(v)
     end
end

As for bindfloat(), it can be something like so,

local function bindfloat(obj)
	spawn(function()
		while true do
			wait(0.1)
			local v = obj
			for i = 1, 5 do
				wait(0.1)
				v.Position = v.Position + Vector3.new(0,i/40.0)
			end
			for i = 4, 1, -1 do
				wait(0.1)
				v.Position = v.Position + Vector3.new(0,i/40.0)
			end
			wait(0.1)
			for i = 1, 5 do
				wait(0.1)
				v.Position = v.Position + Vector3.new(0,i/40.0)
			end
			for i = 4, 1, -1 do
				wait(0.1)
				v.Position = v.Position + Vector3.new(0,i/40.0)
			end
		end  
	end)
end

Just for your information however, there are more efficient ways to make an object float, I used your code as an example since you provided us with that one :+1:

2 Likes

[Float:4: attempt to call global ‘bindfloat’ (a nil value)]
error:

1 Like

Oh you just need to copy the bindfloat function I provided and paste it above the first one :+1:

EDIT : Actually give me a moment, I’ll write you a script to get what you what to achieve

1 Like

Ok, thank you :slight_smile:, i fixed it but the only problem im having now is that it only goes up and doesnt go down :confused:

1 Like
local par = script.Parent
local TS = game:GetService('TweenService')
local tinfo = TweenInfo.new(4,Enum.EasingStyle.Quad,Enum.EasingDirection.In)

local function bindfloat(obj)
	local anims = {}
	anims.Up = TS:Create(obj,tinfo,{Position = obj.Position + Vector3.new(0,5,0)})
	anims.Down = TS:Create(obj,tinfo,{Position = obj.Position})
	anims.Up.Completed:Connect(function()
		wait(.2)
		anims.Down:Play()
	end)
	anims.Down.Completed:Connect(function()
		wait(.4)
		anims.Up:Play()
	end)
	
	anims.Up:Play()
end

for i,v in pairs(par:GetDescendants())do
	if v:IsA'BasePart' then
		bindfloat(v)
	end
end

You can play around with the duration and easing styles/direction to make the float up/down more fluid :+1:

Educational Resources

TweenService | Documentation - Roblox Creator Hub
EasingStyle | Documentation - Roblox Creator Hub
Instance | Documentation - Roblox Creator Hub
Instance | Documentation - Roblox Creator Hub
TweenInfo | Documentation - Roblox Creator Hub

2 Likes