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
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
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)
part2.Anchored = false
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)
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
I made my moderation report before user added more information to question - this can probably be ignored now.