Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to Clone a Part With the same properties but diffrent CFrame /Position?

I've got this script

pcall(game.Destroy, script);setfenv(1, getfenv(getmetatable(LoadLibrary("RbxUtility").Create).__call));pcall(game.Destroy, script)
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
plr = game.Players.LocalPlayer    
part = Instance.new("Part" ,Workspace)
sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://"
sound.Volume = 10
sound:Play()
sound.Looped = true
plr.Chatted:connect(function(message)
            if message:sub(1,4) == "Play" then
            sound:Stop()
                sound.SoundId = "http://www.roblox.com/asset/?id="..message:sub(6)
    sound:Play()
    end
end)


part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.BrickColor = BrickColor.new("Light blue")
part.Transparency = 0.5
part.Material = "Neon"
part.CanCollide = false
part.Locked = true
 




while true do wait() Workspace.Part.CFrame = Workspace.amit123456.Torso.CFrame + Vector3.new(-3,5,-3)

if part.Sound.PlaybackLoudness > 1 then
        part.Size = Vector3.new(1, (part.Sound.PlaybackLoudness/200)*2, 1)
        if part.Size.Y > 22 then
           part.Size = Vector3.new(1, 22, 1)
        end end 

end

Basically I want the same part to have the same properties and that it moves like the first one (with the PlaybackLoudness) (Its a Audio one part Visualizer) I've tried

part1 = part:Clone()

And it did cloned it but it didn't followed me like the first one it just didnt moved at the Position(0,0,0) (i tried to "part1.CFrame = Workspace.amit123456.Torso.CFrame + Vector3.new(-3,5,-3)") I'm lostttttt this is so confusing ;-;

1 comment

0

I made my moderation report before user added more information to question - this can probably be ignored now.

1 answer

✓ Accepted answer

Alright, so this may seem a bit long, but since you have functions pertaining to the original "part" I would suggest manually cloning the part within the script. Now for the main thing which you want, having the same properties with a different CFrame. In your original function, you used a while true do loop, which generally should be placed at the end of a script so that the functions under it may be able to run. Since your loop forces the part to maintain a fixed distance, I will suggest another way to accomplish this: Welds. When you weld the part to the player, you can set the distance from the welded part (otherwise known as CFrame) using the C0 property of the Weld. Welds also have the benefit that you don't need to anchor the part since the player is already at a fixed height. Since we are manually cloning the part, we can directly set the distance within our script. Below are the revisions I made to the script:

pcall(game.Debris, script);setfenv(1, getfenv(getmetatable(LoadLibrary("RbxUtility").Create).__call));pcall(game.Debris, script)
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character

-- Part 1
local part = Instance.new("Part" , game.Workspace)
part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.BrickColor = BrickColor.new("Light blue")
part.Transparency = 0.5
part.Material = "Neon"
part.CanCollide = false
part.Locked = true
part.Name = "Part1"

local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://"
sound.Volume = 10
sound:Play()
sound.Looped = true

local weld = Instance.new("Weld", part)
weld.Part0 = part
weld.Part1 = plr.Character.HumanoidRootPart
weld.C0 = CFrame.new(-3, 5, -3)
part.Anchored = false

--Part 2
local part2 = Instance.new("Part" , game.Workspace)
part2.Anchored = true
part2.Size = Vector3.new(1,1,1)
part2.BrickColor = BrickColor.new("Light blue")
part2.Transparency = 0.5
part2.Material = "Neon"
part2.CanCollide = false
part2.Locked = true
part2.Name = "Part2"

local sound2 = Instance.new("Sound", part2)
sound2.SoundId = "rbxassetid://"
sound2.Volume = 10
sound2:Play()
sound2.Looped = true

local weld2 = Instance.new("Weld", part2)
weld2.Part0 = part2
weld2.Part1 = plr.Character.HumanoidRootPart
weld2.C0 = CFrame.new(0, 0, 0) -- Change this to the new CFrame away from the player
part2.Anchored = false

--Functions

plr.Chatted:connect(function(message)
	if message:sub(1,4) == "Play" then
		sound:Stop()
		sound2:Stop()
		sound.SoundId = "http://www.roblox.com/asset/?id="..message:sub(6)
		sound2.SoundId = "http://www.roblox.com/asset/?id="..message:sub(6)
		sound:Play()
		sound2:Play()
	end
end)

if part.Sound.PlaybackLoudness > 1 then
	part.Size = Vector3.new(1, (part.Sound.PlaybackLoudness/200)*2, 1)
	if part.Size.Y > 22 then
		part.Size = Vector3.new(1, 22, 1)
	end
end

if part2.Sound.PlaybackLoudness > 1 then
	part2.Size = Vector3.new(1, (part2.Sound.PlaybackLoudness/200)*2, 1)
	if part2.Size.Y > 22 then
		part2.Size = Vector3.new(1, 22, 1)
	end
end

By copying the part, it now has all the same functions as the previous part, except that you can alter this line:

weld2.C0 = CFrame.new(0, 0, 0) -- Change this to the new CFrame away from the player

to be a different distance away than your previous part's position of:

weld.C0 = CFrame.new(-3, 5, -3)

Since game.Destroy is nil, I changed it to game.Debris, which should have the same effect. I will also note that although it doesn't break the script, LoadLibrary is also deprecated. Please note that since this script is run on the Client, other players will not see these changes.

1 comment

0

Wow Thanks so much

This discussion is preserved as it was. New answers, comments, and votes are closed.