How to change Y level of multiple instances?

How do I change the Y level of multiple instances?

What I’ve got:

local plr = game.Players.LocalPlayer
local CloudF = game.Workspace.Clouds
local char = plr.Character
local essence = plr:WaitForChild("leaderstats"):WaitForChild("Essence") --Just to make sure the are loaded

while true do
	local Clouds = CloudF:GetChildren()
	Clouds.CFrame.Y = (plr.leaderstats.Essence.Value / 25) + 3.5
	wait()
end

You would need to use for i,v in pairs do loop.

local plr = game.Players.LocalPlayer
local CloudF = game.Workspace.Clouds
local char = plr.Character
local essence = plr:WaitForChild("leaderstats"):WaitForChild("Essence") --Just to make sure the are loaded

while true do
	local Clouds = CloudF:GetChildren()
        for _,v in Clouds do
        v.Position += Vector3.new(0,(plr.leaderstats.Essence.Value / 25) + 3.5,0)
        end
	wait()
end
2 Likes

Ah yes, the one thing I don’t know how to do :skull:

local InstanceWhereToSearch = Path

for index, Instance in pairs(InstanceWhereToSearch:GetChildren()) do

end

I have edited my reply ( i wrote the code on mobile so check for syntax errors before testing)

This is perfect! Well almost perfect… v.Position += Vector3.new(0,(plr.leaderstats.Essence.Value / 25),0 adds the value instead of setting it, causing the clouds to ascend to the heavens :skull: I tried using = instead of += but they just started glitching out even more. Thoughts?

Using = instead of += will fix that tho

local plr = game.Players.LocalPlayer
local CloudF = game.Workspace.Clouds
local char = plr.Character
local essence = plr:WaitForChild("leaderstats"):WaitForChild("Essence") --Just to make sure the are loaded

while task.wait() do
	local Clouds = CloudF:GetChildren()
        for _,v in Clouds do
        v.Position = Vector3.new(0,(plr.leaderstats.Essence.Value / 25) + 3.5,0)
        end
end

Unfortunately not, this causes them to get put at the correct height, but also at x = 0 and z = 0. We need the 0’s copy v’s x and z position. So all thats needed to do is make 2 variables as v’s x and z and use that in the position. Quick question though how do I access that value (forgot if it was cframe or position or what lol)

You can get the X or Z from the v.Position like this:

local plr = game.Players.LocalPlayer
local CloudF = game.Workspace.Clouds
local char = plr.Character
local essence = plr:WaitForChild("leaderstats"):WaitForChild("Essence") --Just to make sure the are loaded

while task.wait() do
	local Clouds = CloudF:GetChildren()
        for _,v in Clouds do
        local x = v.Position.X
        local z = v.Position.Z
        v.Position = Vector3.new(x,(plr.leaderstats.Essence.Value / 25) + 3.5,z)
        end
end

ty for the help again lol. :+1:

1 Like