Locked parts moving on reset

Hey everyone,
I have made a simple audio visualizer that works fine but everytime I reset the whole thing moves up?!
I just cant figure out why that happens.

Proof: https://streamable.com/rlpkgw

local part = game.Workspace.Audios.bars.Audio
local part2 = game.Workspace.Audios.bars.Audio2
local part3 = game.Workspace.Audios.bars.Audio3
local part4 = game.Workspace.Audios.bars.Audio4
local part5 = game.Workspace.Audios.bars.Audio5




local sizex = part.Size.X
local sizez = part.Size.Z
local positiony = part.Position.Y
local positionx = part.Position.X
local positionz = part.Position.Z

local sizex2 = part2.Size.X
local sizez2 = part2.Size.Z
local positiony2 = part2.Position.Y
local positionx2 = part2.Position.X
local positionz2 = part2.Position.Z

local sizex3 = part3.Size.X
local sizez3 = part3.Size.Z
local positiony3 = part3.Position.Y
local positionx3 = part3.Position.X
local positionz3 = part3.Position.Z

local sizex4 = part4.Size.X
local sizez4 = part4.Size.Z
local positiony4 = part4.Position.Y
local positionx4 = part4.Position.X
local positionz4 = part4.Position.Z

local sizex5 = part5.Size.X
local sizez5 = part5.Size.Z
local positiony5 = part5.Position.Y
local positionx5 = part5.Position.X
local positionz5 = part5.Position.Z


game:GetService("RunService").RenderStepped:Connect(function()
	
	local loudness = game.Workspace.music_system.Sound.PlaybackLoudness
	local sizeincrement = loudness/60
	
	part.Size = Vector3.new(sizex, sizeincrement, sizez)
	part.Position = Vector3.new(positionx, positiony + (sizeincrement/2), positionz)
	
	part2.Size = Vector3.new(sizex2, sizeincrement, sizez2)
	part2.Position = Vector3.new(positionx2, positiony2 + (sizeincrement/2), positionz2)
	
	part3.Size = Vector3.new(sizex3, sizeincrement, sizez3)
	part3.Position = Vector3.new(positionx3, positiony3 + (sizeincrement/2), positionz3)
	
	part4.Size = Vector3.new(sizex4, sizeincrement, sizez4)
	part4.Position = Vector3.new(positionx4, positiony4 + (sizeincrement/2), positionz4)
	
	part5.Size = Vector3.new(sizex5, sizeincrement, sizez5)
	part5.Position = Vector3.new(positionx5, positiony5 + (sizeincrement/2), positionz5)
	

	
	
	--print(loudness)
	
	
	if loudness >= 75 then
		
		part.Material = "Neon"
		part.BrickColor = BrickColor.new(0.160784, 0.313725, 1)
		part2.Material = "Neon"
		part2.BrickColor = BrickColor.new(0.160784, 0.313725, 1)
		part3.Material = "Neon"
		part3.BrickColor = BrickColor.new(0.160784, 0.313725, 1)
		part4.Material = "Neon"
		part4.BrickColor = BrickColor.new(0.160784, 0.313725, 1)
		part5.Material = "Neon"
		part5.BrickColor = BrickColor.new(0.160784, 0.313725, 1)
		
	else
		
		part.Material = "Plastic"
		part.BrickColor = BrickColor.new(0,0,0)
		part2.Material = "Plastic"
		part2.BrickColor = BrickColor.new(0,0,0)
		part3.Material = "Plastic"
		part3.BrickColor = BrickColor.new(0,0,0)
		part4.Material = "Plastic"
		part4.BrickColor = BrickColor.new(0,0,0)
		part5.Material = "Plastic"
		part5.BrickColor = BrickColor.new(0,0,0)
		
	end
end)
 

The script is a Local script in StarterGUI, the visualizer itself works for everyone but when I reset it moves up.

Thanks for your help!

The visualizer is in the form of BaseParts, not GuiObject, you should read the post and look at the code again

When a character respawns, both the contents of StarterGUI and StarterCharacterScripts will be restarted. The GUI of the player will be emptied and recopied from the StarterGUI (Unless you set the property of ResetOnSpawn of a particular ScreenGUI to false). Local Scripts in StarterCharacterScripts will also be re-parented and re-run on respawn. In your case, the visualizer does some modifications to your parts, and when you die the script assigns those modified vectors to your variables - everytime.

You have several ways of going about this here.

Since I see no GUI involved here, you can move this to StarterCharacterScripts and set the size and position of each part to their absolute original values (not by getting them through properties) at their declaration before the RenderStepped event, so everytime the character respawns the parts will be set to their default positions and sizes.

Or even better, moving the script to StarterPlayerScripts since that’ll make the script persistent and will run only once when the player joins the game.

1 Like

Thanks alot, this solved my problem!
I actually learned something new aswell.