Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Converted with ttyyuu12345's model to script plugin v4
- function sandbox(var,func)
- local env = getfenv(func)
- local newenv = setmetatable({},{
- __index = function(self,k)
- if k=="script" then
- return var
- else
- return env[k]
- end
- end,
- })
- setfenv(func,newenv)
- return func
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- Model0 = Instance.new("Model")
- Part1 = Instance.new("Part")
- Weld2 = Instance.new("Weld")
- SpecialMesh3 = Instance.new("SpecialMesh")
- Decal4 = Instance.new("Decal")
- Sound5 = Instance.new("Sound")
- Part6 = Instance.new("Part")
- Decal7 = Instance.new("Decal")
- Motor6D8 = Instance.new("Motor6D")
- Motor6D9 = Instance.new("Motor6D")
- Motor6D10 = Instance.new("Motor6D")
- Motor6D11 = Instance.new("Motor6D")
- Motor6D12 = Instance.new("Motor6D")
- Part13 = Instance.new("Part")
- Part14 = Instance.new("Part")
- Part15 = Instance.new("Part")
- Script16 = Instance.new("Script")
- Part17 = Instance.new("Part")
- Script18 = Instance.new("Script")
- BoolValue19 = Instance.new("BoolValue")
- Script20 = Instance.new("Script")
- BoolValue21 = Instance.new("BoolValue")
- Humanoid22 = Instance.new("Humanoid")
- ObjectValue23 = Instance.new("ObjectValue")
- Script24 = Instance.new("Script")
- Script25 = Instance.new("Script")
- Script26 = Instance.new("Script")
- NumberValue27 = Instance.new("NumberValue")
- ObjectValue28 = Instance.new("ObjectValue")
- Animation29 = Instance.new("Animation")
- Script30 = Instance.new("Script")
- StringValue31 = Instance.new("StringValue")
- Animation32 = Instance.new("Animation")
- StringValue33 = Instance.new("StringValue")
- Animation34 = Instance.new("Animation")
- StringValue35 = Instance.new("StringValue")
- Animation36 = Instance.new("Animation")
- NumberValue37 = Instance.new("NumberValue")
- Animation38 = Instance.new("Animation")
- NumberValue39 = Instance.new("NumberValue")
- StringValue40 = Instance.new("StringValue")
- Animation41 = Instance.new("Animation")
- StringValue42 = Instance.new("StringValue")
- Animation43 = Instance.new("Animation")
- StringValue44 = Instance.new("StringValue")
- Animation45 = Instance.new("Animation")
- StringValue46 = Instance.new("StringValue")
- Animation47 = Instance.new("Animation")
- StringValue48 = Instance.new("StringValue")
- Animation49 = Instance.new("Animation")
- Camera50 = Instance.new("Camera")
- Pants51 = Instance.new("Pants")
- Shirt52 = Instance.new("Shirt")
- Folder53 = Instance.new("Folder")
- Sound54 = Instance.new("Sound")
- Script55 = Instance.new("Script")
- Script56 = Instance.new("Script")
- LocalScript57 = Instance.new("LocalScript")
- ScreenGui58 = Instance.new("ScreenGui")
- TextButton59 = Instance.new("TextButton")
- ModuleScript60 = Instance.new("ModuleScript")
- Model0.Name = "Zombie Yeti"
- Model0.Parent = mas
- Part1.Name = "Head"
- Part1.Parent = Model0
- Part1.CFrame = CFrame.new(-6.13871002, 9.14999771, -11.4352522, -0.999999821, 1.33315838e-08, -2.98023224e-08, 1.33315865e-08, 1, 4.03998524e-09, 2.98023224e-08, 4.03997991e-09, -0.999999821)
- Part1.Orientation = Vector3.new(0, -180, 0)
- Part1.Position = Vector3.new(-6.13871002, 9.14999771, -11.4352522)
- Part1.Rotation = Vector3.new(-180, 0, -180)
- Part1.Color = Color3.new(0.94902, 0.952941, 0.952941)
- Part1.Size = Vector3.new(4, 2, 2)
- Part1.BrickColor = BrickColor.new("White")
- Part1.TopSurface = Enum.SurfaceType.Smooth
- Part1.brickColor = BrickColor.new("White")
- Part1.FormFactor = Enum.FormFactor.Symmetric
- Part1.formFactor = Enum.FormFactor.Symmetric
- Weld2.Name = "HeadWeld"
- Weld2.Parent = Part1
- Weld2.C0 = CFrame.new(0, 0.5, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Weld2.C1 = CFrame.new(0, 0.25, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- SpecialMesh3.Parent = Part1
- SpecialMesh3.Scale = Vector3.new(1.25, 1.25, 1.25)
- Decal4.Name = "Papyrus Face"
- Decal4.Parent = Part1
- Decal4.Texture = "http://www.roblox.com/asset/?id=785118827"
- Sound5.Name = "Undertale - Genocide Papyrus [Backbone]"
- Sound5.Parent = Part1
- Sound5.SoundId = "rbxassetid://321451733"
- Part6.Name = "Torso"
- Part6.Parent = Model0
- Part6.CFrame = CFrame.new(-6.13871002, 5.99999809, -11.4352522, -0.999999821, 1.33315838e-08, -2.98023224e-08, 1.33315865e-08, 1, 4.03998524e-09, 2.98023224e-08, 4.03997991e-09, -0.999999821)
- Part6.Orientation = Vector3.new(0, -180, 0)
- Part6.Position = Vector3.new(-6.13871002, 5.99999809, -11.4352522)
- Part6.Rotation = Vector3.new(-180, 0, -180)
- Part6.Color = Color3.new(0.94902, 0.952941, 0.952941)
- Part6.Size = Vector3.new(4, 4, 2)
- Part6.BrickColor = BrickColor.new("White")
- Part6.LeftParamA = 0
- Part6.LeftParamB = 0
- Part6.LeftSurface = Enum.SurfaceType.Weld
- Part6.Material = Enum.Material.Ice
- Part6.RightParamA = 0
- Part6.RightParamB = 0
- Part6.RightSurface = Enum.SurfaceType.Weld
- Part6.brickColor = BrickColor.new("White")
- Part6.FormFactor = Enum.FormFactor.Symmetric
- Part6.formFactor = Enum.FormFactor.Symmetric
- Decal7.Name = "roblox"
- Decal7.Parent = Part6
- Motor6D8.Name = "Right Shoulder"
- Motor6D8.Parent = Part6
- Motor6D8.MaxVelocity = 0.15000000596046
- Motor6D8.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
- Motor6D8.C1 = CFrame.new(-2, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
- Motor6D8.Part0 = Part6
- Motor6D8.Part1 = Part14
- Motor6D8.part1 = Part14
- Motor6D9.Name = "Left Shoulder"
- Motor6D9.Parent = Part6
- Motor6D9.MaxVelocity = 0.15000000596046
- Motor6D9.C0 = CFrame.new(-1, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
- Motor6D9.C1 = CFrame.new(1.99999976, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
- Motor6D9.Part0 = Part6
- Motor6D9.Part1 = Part13
- Motor6D9.part1 = Part13
- Motor6D10.Name = "Right Hip"
- Motor6D10.Parent = Part6
- Motor6D10.MaxVelocity = 0.10000000149012
- Motor6D10.C0 = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
- Motor6D10.C1 = CFrame.new(0, 3, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
- Motor6D10.Part0 = Part6
- Motor6D10.Part1 = Part17
- Motor6D10.part1 = Part17
- Motor6D11.Name = "Left Hip"
- Motor6D11.Parent = Part6
- Motor6D11.MaxVelocity = 0.10000000149012
- Motor6D11.C0 = CFrame.new(-1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
- Motor6D11.C1 = CFrame.new(0, 3, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
- Motor6D11.Part0 = Part6
- Motor6D11.Part1 = Part15
- Motor6D11.part1 = Part15
- Motor6D12.Name = "Neck"
- Motor6D12.Parent = Part6
- Motor6D12.C1 = CFrame.new(0, 3.1500001, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Motor6D12.Part0 = Part1
- Motor6D12.Part1 = Part6
- Motor6D12.part1 = Part6
- Part13.Name = "Left Arm"
- Part13.Parent = Model0
- Part13.CFrame = CFrame.new(-3.13871074, 5.99999809, -11.4352522, -0.999999821, 1.33315838e-08, -2.98023224e-08, 1.33315865e-08, 1, 4.03998524e-09, 2.98023224e-08, 4.03997991e-09, -0.999999821)
- Part13.Orientation = Vector3.new(0, -180, 0)
- Part13.Position = Vector3.new(-3.13871074, 5.99999809, -11.4352522)
- Part13.Rotation = Vector3.new(-180, 0, -180)
- Part13.Color = Color3.new(0.94902, 0.952941, 0.952941)
- Part13.Size = Vector3.new(2, 4, 2)
- Part13.BottomSurface = Enum.SurfaceType.Smooth
- Part13.BrickColor = BrickColor.new("White")
- Part13.CanCollide = false
- Part13.Material = Enum.Material.Ice
- Part13.brickColor = BrickColor.new("White")
- Part13.FormFactor = Enum.FormFactor.Symmetric
- Part13.formFactor = Enum.FormFactor.Symmetric
- Part14.Name = "Right Arm"
- Part14.Parent = Model0
- Part14.CFrame = CFrame.new(-9.13871002, 5.99999809, -11.4352522, -0.999999821, 1.33315838e-08, -2.98023224e-08, 1.33315865e-08, 1, 4.03998524e-09, 2.98023224e-08, 4.03997991e-09, -0.999999821)
- Part14.Orientation = Vector3.new(0, -180, 0)
- Part14.Position = Vector3.new(-9.13871002, 5.99999809, -11.4352522)
- Part14.Rotation = Vector3.new(-180, 0, -180)
- Part14.Color = Color3.new(0.94902, 0.952941, 0.952941)
- Part14.Size = Vector3.new(2, 4, 2)
- Part14.BottomSurface = Enum.SurfaceType.Smooth
- Part14.BrickColor = BrickColor.new("White")
- Part14.CanCollide = false
- Part14.Material = Enum.Material.Ice
- Part14.brickColor = BrickColor.new("White")
- Part14.FormFactor = Enum.FormFactor.Symmetric
- Part14.formFactor = Enum.FormFactor.Symmetric
- Part15.Name = "Left Leg"
- Part15.Parent = Model0
- Part15.CFrame = CFrame.new(-5.13871002, 1.99999809, -11.4352522, -0.999999821, 1.33315838e-08, -2.98023224e-08, 1.33315865e-08, 1, 4.03998524e-09, 2.98023224e-08, 4.03997991e-09, -0.999999821)
- Part15.Orientation = Vector3.new(0, -180, 0)
- Part15.Position = Vector3.new(-5.13871002, 1.99999809, -11.4352522)
- Part15.Rotation = Vector3.new(-180, 0, -180)
- Part15.Color = Color3.new(0.94902, 0.952941, 0.952941)
- Part15.Size = Vector3.new(2, 4, 2)
- Part15.BottomSurface = Enum.SurfaceType.Smooth
- Part15.BrickColor = BrickColor.new("White")
- Part15.CanCollide = false
- Part15.Material = Enum.Material.Ice
- Part15.brickColor = BrickColor.new("White")
- Part15.FormFactor = Enum.FormFactor.Symmetric
- Part15.formFactor = Enum.FormFactor.Symmetric
- Script16.Parent = Part15
- table.insert(cors,sandbox(Script16,function()
- function touch(hit)
- if hit.Parent.Name == "Tank" or hit.Parent.Name == "Brotherhood Of Scythe" then
- script.Parent.Parent.Humanoid.Jump = true
- end
- end
- script.Parent.Touched:connect(touch)
- while true do
- touch = script.Parent:findFirstChild("TouchInterest")
- if touch == nil then
- script.Parent.Touched:connect(touch)
- end
- wait()
- end
- end))
- Part17.Name = "Right Leg"
- Part17.Parent = Model0
- Part17.CFrame = CFrame.new(-7.13871002, 1.99999809, -11.4352522, -0.999999821, 1.33315838e-08, -2.98023224e-08, 1.33315865e-08, 1, 4.03998524e-09, 2.98023224e-08, 4.03997991e-09, -0.999999821)
- Part17.Orientation = Vector3.new(0, -180, 0)
- Part17.Position = Vector3.new(-7.13871002, 1.99999809, -11.4352522)
- Part17.Rotation = Vector3.new(-180, 0, -180)
- Part17.Color = Color3.new(0.94902, 0.952941, 0.952941)
- Part17.Size = Vector3.new(2, 4, 2)
- Part17.BottomSurface = Enum.SurfaceType.Smooth
- Part17.BrickColor = BrickColor.new("White")
- Part17.CanCollide = false
- Part17.Material = Enum.Material.Ice
- Part17.brickColor = BrickColor.new("White")
- Part17.FormFactor = Enum.FormFactor.Symmetric
- Part17.formFactor = Enum.FormFactor.Symmetric
- Script18.Parent = Part17
- table.insert(cors,sandbox(Script18,function()
- function touch(hit)
- if hit.Parent.Name == "Tank" or hit.Parent.Name == "Brotherhood Of Scythe" then
- script.Parent.Parent.Humanoid.Jump = true
- end
- end
- script.Parent.Touched:connect(touch)
- while true do
- touch = script.Parent:findFirstChild("TouchInterest")
- if touch == nil then
- script.Parent.Touched:connect(touch)
- end
- wait()
- end
- end))
- BoolValue19.Name = "Attack"
- BoolValue19.Parent = Model0
- Script20.Name = "ChaseScript"
- Script20.Parent = Model0
- table.insert(cors,sandbox(Script20,function()
- wait()
- zombieParent = false
- while zombieParent == false do
- wait()
- if script.Parent.Name == "Zombie Yeti" then
- zombieParent = true
- end
- end
- local larm = script.Parent:FindFirstChild("Left Arm")
- local rarm = script.Parent:FindFirstChild("Right Arm")
- local waitTimer = 0
- function findNearestTorso(pos)
- local list = game.Workspace:children()
- local torso = nil
- local dist = 10000
- local temp = nil
- local human = nil
- local temp2 = nil
- for x = 1, #list do
- temp2 = list[x]
- if (temp2.className == "Model") and (temp2 ~= script.Parent) then
- temp = temp2:findFirstChild("Torso")
- human = temp2:findFirstChild("Humanoid")
- if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
- if (temp.Position - pos).magnitude < dist then
- torso = temp
- script.Parent.Target.Value = temp
- dist = (temp.Position - pos).magnitude
- if human.Health >= 1 then
- script.Parent.Range.Value = true
- else
- script.Parent.Range.Value = false
- end
- end
- end
- if dist < 10 then
- script.Parent.Attack.Value = true
- else
- script.Parent.Attack.Value = false
- end
- end
- end
- return torso
- end
- function Sit()
- if script.Parent.Zombie.Sit == true then
- script.Parent.Zombie.Jump = true
- print("Anti Seat Putter!!!")
- end
- end
- script.Parent.Zombie.Changed:connect(Sit)
- function touch(hit)
- if hit and hit.Parent then
- if hit.Parent.Name == "Ballista" or hit.Parent.Name == "Brotherhood Of Scythe" or hit.Parent.Name == "Jump" then
- script.Parent.Zombie.Jump = true
- end
- end
- end
- script.Parent["Right Leg"].Touched:connect(touch)
- script.Parent["Left Leg"].Touched:connect(touch)
- while true do
- wait(1)
- local target = findNearestTorso(script.Parent.Torso.Position)
- if target ~= nil then
- rx = math.random(-3,3)
- ry = math.random(0,0)
- rz = math.random(-3,3)
- script.Parent.Zombie:MoveTo(target.Position+Vector3.new(rx,ry,rz), target)
- else
- script.Parent.Range.Value = false
- script.Parent.Attack.Value = false
- end
- end
- end))
- BoolValue21.Name = "Range"
- BoolValue21.Parent = Model0
- Humanoid22.Name = "Zombie"
- Humanoid22.Parent = Model0
- Humanoid22.Health = 4752
- Humanoid22.LeftLeg = Part15
- Humanoid22.MaxHealth = 4752
- Humanoid22.NameOcclusion = Enum.NameOcclusion.NoOcclusion
- Humanoid22.RightLeg = Part17
- Humanoid22.Torso = Part6
- Humanoid22.WalkSpeed = 75
- Humanoid22.maxHealth = 4752
- ObjectValue23.Name = "Target"
- ObjectValue23.Parent = Model0
- Script24.Name = "Die"
- Script24.Parent = Model0
- table.insert(cors,sandbox(Script24,function()
- human = script.Parent.Zombie
- --tool = script.Parent.Pistol
- function Die()
- --if tool ~= nil then tool:remove() end
- wait(2.5)
- script.Parent:remove()
- end
- human.Died:connect(Die)
- end))
- Script25.Name = "ZombieScript"
- Script25.Parent = Model0
- table.insert(cors,sandbox(Script25,function()
- wait(1.5)
- local sp = script.Parent
- local Humanoid = sp:WaitForChild("Zombie")
- local Head = sp:WaitForChild("Head")
- local Torso = sp:WaitForChild("Torso")
- local Animation = script:WaitForChild("AttackAnim")
- local Yeti = Instance.new("Sound",Torso)
- Yeti.Volume = 1
- Yeti.SoundId = "http://www.roblox.com/asset/?id=38212101"
- Spawn(function() Yeti:Play() end)
- local Hit1 = Instance.new("Sound",Torso)
- Hit1.Volume = 1
- Hit1.SoundId = "http://www.roblox.com/asset/?id=2801263"
- local Hit2 = Instance.new("Sound",Torso)
- Hit2.Volume = 1
- Hit2.SoundId = "http://www.roblox.com/asset/?id=38212101"
- local AttackEnabled = true
- function wait(TimeToWait)
- if TimeToWait ~= nil then
- local TotalTime = 0
- TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
- while TotalTime < TimeToWait do
- TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
- end
- else
- game:GetService("RunService").Heartbeat:wait()
- end
- end
- function DamageTag(parent,damage)
- local DmgTag = script.DamageTag:clone()
- DmgTag.Damage.Value = damage
- DmgTag.creator.Value = game.Players.LocalPlayer
- DmgTag.Disabled = false
- DmgTag.Parent = parent
- end
- local Anim = Humanoid:LoadAnimation(Animation)
- function Hit(hit)
- local TargetHum = hit.Parent:FindFirstChild("Humanoid")
- if TargetHum ~= nil and TargetHum:IsA("Humanoid") and AttackEnabled == true and TargetHum ~= Humanoid then
- AttackEnabled = false
- Delay(0.5,function() AttackEnabled = true end)
- if Anim then Anim:Play(nil,nil,1.5) end
- DamageTag(TargetHum.Parent,125)
- Hit1:Play()
- Hit2:Play()
- end
- end
- for _, Child in pairs(script.Parent:GetChildren()) do
- if Child:IsA("Part") or Child:IsA("WedgePart") or Child:IsA("CornerWedgePart") then
- Child.Touched:connect(Hit)
- end
- end
- end))
- Script26.Name = "DamageTag"
- Script26.Parent = Script25
- table.insert(cors,sandbox(Script26,function()
- wait()
- h = script.Parent:findFirstChild("Humanoid")
- if h ~= nil then
- while h:findFirstChild("creator") do
- h.creator:Destroy()
- end
- tag = script.creator:clone()
- tag.Parent = h
- game.Debris:AddItem(tag,5)
- h:TakeDamage(script.Damage.Value)
- end
- script:remove()
- end))
- Script26.Disabled = true
- NumberValue27.Name = "Damage"
- NumberValue27.Parent = Script26
- ObjectValue28.Name = "creator"
- ObjectValue28.Parent = Script26
- Animation29.Name = "AttackAnim"
- Animation29.Parent = Script25
- Animation29.AnimationId = "http://www.roblox.com/Asset?ID=105211514"
- Script30.Name = "Animate"
- Script30.Parent = Model0
- table.insert(cors,sandbox(Script30,function()
- function waitForChild(parent, childName)
- local child = parent:findFirstChild(childName)
- if child then return child end
- while true do
- child = parent.ChildAdded:wait()
- if child.Name==childName then return child end
- end
- end
- local Figure = script.Parent
- local Torso = waitForChild(Figure, "Torso")
- local RightShoulder = waitForChild(Torso, "Right Shoulder")
- local LeftShoulder = waitForChild(Torso, "Left Shoulder")
- local RightHip = waitForChild(Torso, "Right Hip")
- local LeftHip = waitForChild(Torso, "Left Hip")
- local Neck = waitForChild(Torso, "Neck")
- local Zombie = waitForChild(Figure, "Zombie")
- local pose = "Standing"
- local currentAnim = ""
- local currentAnimInstance = nil
- local currentAnimTrack = nil
- local currentAnimKeyframeHandler = nil
- local currentAnimSpeed = 1.0
- local animTable = {}
- local animNames = {
- idle = {
- { id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
- { id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
- },
- walk = {
- { id = "http://www.roblox.com/asset/?id=180426354", weight = 10 }
- },
- run = {
- { id = "run.xml", weight = 10 }
- },
- jump = {
- { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
- },
- fall = {
- { id = "http://www.roblox.com/asset/?id=305752857", weight = 10 }
- },
- climb = {
- { id = "http://www.roblox.com/asset/?id=180436334", weight = 10 }
- },
- sit = {
- { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
- },
- toolnone = {
- { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
- },
- toolslash = {
- { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
- -- { id = "slash.xml", weight = 10 }
- },
- toollunge = {
- { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
- },
- wave = {
- { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
- },
- point = {
- { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
- },
- dance = {
- { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
- },
- dance2 = {
- { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
- },
- dance3 = {
- { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
- },
- laugh = {
- { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
- },
- cheer = {
- { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
- },
- }
- -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
- local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
- math.randomseed(tick())
- function configureAnimationSet(name, fileList)
- if (animTable[name] ~= nil) then
- for _, connection in pairs(animTable[name].connections) do
- connection:disconnect()
- end
- end
- animTable[name] = {}
- animTable[name].count = 0
- animTable[name].totalWeight = 0
- animTable[name].connections = {}
- -- check for config values
- local config = script:FindFirstChild(name)
- if (config ~= nil) then
- -- print("Loading anims " .. name)
- table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
- table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
- local idx = 1
- for _, childPart in pairs(config:GetChildren()) do
- if (childPart:IsA("Animation")) then
- table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
- animTable[name][idx] = {}
- animTable[name][idx].anim = childPart
- local weightObject = childPart:FindFirstChild("Weight")
- if (weightObject == nil) then
- animTable[name][idx].weight = 1
- else
- animTable[name][idx].weight = weightObject.Value
- end
- animTable[name].count = animTable[name].count + 1
- animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
- -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
- idx = idx + 1
- end
- end
- end
- -- fallback to defaults
- if (animTable[name].count <= 0) then
- for idx, anim in pairs(fileList) do
- animTable[name][idx] = {}
- animTable[name][idx].anim = Instance.new("Animation")
- animTable[name][idx].anim.Name = name
- animTable[name][idx].anim.AnimationId = anim.id
- animTable[name][idx].weight = anim.weight
- animTable[name].count = animTable[name].count + 1
- animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
- -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
- end
- end
- end
- -- Setup animation objects
- function scriptChildModified(child)
- local fileList = animNames[child.Name]
- if (fileList ~= nil) then
- configureAnimationSet(child.Name, fileList)
- end
- end
- script.ChildAdded:connect(scriptChildModified)
- script.ChildRemoved:connect(scriptChildModified)
- for name, fileList in pairs(animNames) do
- configureAnimationSet(name, fileList)
- end
- -- ANIMATION
- -- declarations
- local toolAnim = "None"
- local toolAnimTime = 0
- local jumpAnimTime = 0
- local jumpAnimDuration = 0.3
- local toolTransitionTime = 0.1
- local fallTransitionTime = 0.3
- local jumpMaxLimbVelocity = 0.75
- -- functions
- function stopAllAnimations()
- local oldAnim = currentAnim
- -- return to idle if finishing an emote
- if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
- oldAnim = "idle"
- end
- currentAnim = ""
- currentAnimInstance = nil
- if (currentAnimKeyframeHandler ~= nil) then
- currentAnimKeyframeHandler:disconnect()
- end
- if (currentAnimTrack ~= nil) then
- currentAnimTrack:Stop()
- currentAnimTrack:Destroy()
- currentAnimTrack = nil
- end
- return oldAnim
- end
- function setAnimationSpeed(speed)
- if speed ~= currentAnimSpeed then
- currentAnimSpeed = speed
- currentAnimTrack:AdjustSpeed(currentAnimSpeed)
- end
- end
- function keyFrameReachedFunc(frameName)
- if (frameName == "End") then
- local repeatAnim = currentAnim
- -- return to idle if finishing an emote
- if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
- repeatAnim = "idle"
- end
- local animSpeed = currentAnimSpeed
- playAnimation(repeatAnim, 0.0, Zombie)
- setAnimationSpeed(animSpeed)
- end
- end
- -- Preload animations
- function playAnimation(animName, transitionTime, Zombie)
- local roll = math.random(1, animTable[animName].totalWeight)
- local origRoll = roll
- local idx = 1
- while (roll > animTable[animName][idx].weight) do
- roll = roll - animTable[animName][idx].weight
- idx = idx + 1
- end
- -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
- local anim = animTable[animName][idx].anim
- -- switch animation
- if (anim ~= currentAnimInstance) then
- if (currentAnimTrack ~= nil) then
- currentAnimTrack:Stop(transitionTime)
- currentAnimTrack:Destroy()
- end
- currentAnimSpeed = 1.0
- -- load it to the Zombie; get AnimationTrack
- currentAnimTrack = Zombie:LoadAnimation(anim)
- -- play the animation
- currentAnimTrack:Play(transitionTime)
- currentAnim = animName
- currentAnimInstance = anim
- -- set up keyframe name triggers
- if (currentAnimKeyframeHandler ~= nil) then
- currentAnimKeyframeHandler:disconnect()
- end
- currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
- end
- end
- -------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------
- local toolAnimName = ""
- local toolAnimTrack = nil
- local toolAnimInstance = nil
- local currentToolAnimKeyframeHandler = nil
- function toolKeyFrameReachedFunc(frameName)
- if (frameName == "End") then
- -- print("Keyframe : ".. frameName)
- playToolAnimation(toolAnimName, 0.0, Zombie)
- end
- end
- function playToolAnimation(animName, transitionTime, Zombie)
- local roll = math.random(1, animTable[animName].totalWeight)
- local origRoll = roll
- local idx = 1
- while (roll > animTable[animName][idx].weight) do
- roll = roll - animTable[animName][idx].weight
- idx = idx + 1
- end
- -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
- local anim = animTable[animName][idx].anim
- if (toolAnimInstance ~= anim) then
- if (toolAnimTrack ~= nil) then
- toolAnimTrack:Stop()
- toolAnimTrack:Destroy()
- transitionTime = 0
- end
- -- load it to the Zombie; get AnimationTrack
- toolAnimTrack = Zombie:LoadAnimation(anim)
- -- play the animation
- toolAnimTrack:Play(transitionTime)
- toolAnimName = animName
- toolAnimInstance = anim
- currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
- end
- end
- function stopToolAnimations()
- local oldAnim = toolAnimName
- if (currentToolAnimKeyframeHandler ~= nil) then
- currentToolAnimKeyframeHandler:disconnect()
- end
- toolAnimName = ""
- toolAnimInstance = nil
- if (toolAnimTrack ~= nil) then
- toolAnimTrack:Stop()
- toolAnimTrack:Destroy()
- toolAnimTrack = nil
- end
- return oldAnim
- end
- -------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------
- function onRunning(speed)
- if speed>0.01 then
- playAnimation("walk", 0.1, Zombie)
- if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
- setAnimationSpeed(speed / 14.5)
- end
- pose = "Running"
- else
- playAnimation("idle", 0.1, Zombie)
- pose = "Standing"
- end
- end
- function onDied()
- pose = "Dead"
- end
- function onJumping()
- playAnimation("jump", 0.1, Zombie)
- jumpAnimTime = jumpAnimDuration
- pose = "Jumping"
- end
- function onClimbing(speed)
- playAnimation("climb", 0.1, Zombie)
- setAnimationSpeed(speed / 12.0)
- pose = "Climbing"
- end
- function onGettingUp()
- pose = "GettingUp"
- end
- function onFreeFall()
- if (jumpAnimTime <= 0) then
- playAnimation("fall", fallTransitionTime, Zombie)
- end
- pose = "FreeFall"
- end
- function onFallingDown()
- pose = "FallingDown"
- end
- function onSeated()
- pose = "Seated"
- end
- function onPlatformStanding()
- pose = "PlatformStanding"
- end
- function onSwimming(speed)
- if speed>0 then
- pose = "Running"
- else
- pose = "Standing"
- end
- end
- function getTool()
- for _, kid in ipairs(Figure:GetChildren()) do
- if kid.className == "Tool" then return kid end
- end
- return nil
- end
- function getToolAnim(tool)
- for _, c in ipairs(tool:GetChildren()) do
- if c.Name == "toolanim" and c.className == "StringValue" then
- return c
- end
- end
- return nil
- end
- function animateTool()
- if (toolAnim == "None") then
- playToolAnimation("toolnone", toolTransitionTime, Zombie)
- return
- end
- if (toolAnim == "Slash") then
- playToolAnimation("toolslash", 0, Zombie)
- return
- end
- if (toolAnim == "Lunge") then
- playToolAnimation("toollunge", 0, Zombie)
- return
- end
- end
- function moveSit()
- RightShoulder.MaxVelocity = 0.15
- LeftShoulder.MaxVelocity = 0.15
- RightShoulder:SetDesiredAngle(3.14 /2)
- LeftShoulder:SetDesiredAngle(-3.14 /2)
- RightHip:SetDesiredAngle(3.14 /2)
- LeftHip:SetDesiredAngle(-3.14 /2)
- end
- local lastTick = 0
- function move(time)
- local amplitude = 1
- local frequency = 1
- local deltaTime = time - lastTick
- lastTick = time
- local climbFudge = 0
- local setAngles = false
- if (jumpAnimTime > 0) then
- jumpAnimTime = jumpAnimTime - deltaTime
- end
- if (pose == "FreeFall" and jumpAnimTime <= 0) then
- playAnimation("fall", fallTransitionTime, Zombie)
- elseif (pose == "Seated") then
- playAnimation("sit", 0.5, Zombie)
- return
- elseif (pose == "Running") then
- playAnimation("walk", 0.1, Zombie)
- elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
- -- print("Wha " .. pose)
- stopAllAnimations()
- amplitude = 0.1
- frequency = 1
- setAngles = true
- end
- if (setAngles) then
- desiredAngle = amplitude * math.sin(time * frequency)
- RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
- LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
- RightHip:SetDesiredAngle(-desiredAngle)
- LeftHip:SetDesiredAngle(-desiredAngle)
- end
- -- Tool Animation handling
- local tool = getTool()
- if tool and tool:FindFirstChild("Handle") then
- animStringValueObject = getToolAnim(tool)
- if animStringValueObject then
- toolAnim = animStringValueObject.Value
- -- message recieved, delete StringValue
- animStringValueObject.Parent = nil
- toolAnimTime = time + .3
- end
- if time > toolAnimTime then
- toolAnimTime = 0
- toolAnim = "None"
- end
- animateTool()
- else
- stopToolAnimations()
- toolAnim = "None"
- toolAnimInstance = nil
- toolAnimTime = 0
- end
- end
- -- connect events
- Zombie.Died:connect(onDied)
- Zombie.Running:connect(onRunning)
- Zombie.Jumping:connect(onJumping)
- Zombie.Climbing:connect(onClimbing)
- Zombie.GettingUp:connect(onGettingUp)
- Zombie.FreeFalling:connect(onFreeFall)
- Zombie.FallingDown:connect(onFallingDown)
- Zombie.Seated:connect(onSeated)
- Zombie.PlatformStanding:connect(onPlatformStanding)
- Zombie.Swimming:connect(onSwimming)
- -- setup emote chat hook
- Game.Players.LocalPlayer.Chatted:connect(function(msg)
- local emote = ""
- if (string.sub(msg, 1, 3) == "/e ") then
- emote = string.sub(msg, 4)
- elseif (string.sub(msg, 1, 7) == "/emote ") then
- emote = string.sub(msg, 8)
- end
- if (pose == "Standing" and emoteNames[emote] ~= nil) then
- playAnimation(emote, 0.1, Zombie)
- end
- end)
- -- main program
- local runService = game:service("RunService");
- -- initialize to idle
- playAnimation("idle", 0.1, Zombie)
- pose = "Standing"
- while Figure.Parent~=nil do
- local _, time = wait(0.1)
- move(time)
- end
- end))
- StringValue31.Name = "climb"
- StringValue31.Parent = Script30
- Animation32.Name = "ClimbAnim"
- Animation32.Parent = StringValue31
- Animation32.AnimationId = "http://www.roblox.com/asset/?id=180436334"
- StringValue33.Name = "fall"
- StringValue33.Parent = Script30
- Animation34.Name = "FallAnim"
- Animation34.Parent = StringValue33
- Animation34.AnimationId = "http://www.roblox.com/asset/?id=180436148"
- StringValue35.Name = "idle"
- StringValue35.Parent = Script30
- Animation36.Name = "Animation1"
- Animation36.Parent = StringValue35
- Animation36.AnimationId = "http://www.roblox.com/asset/?id=180435571"
- NumberValue37.Name = "Weight"
- NumberValue37.Parent = Animation36
- NumberValue37.Value = 9
- Animation38.Name = "Animation2"
- Animation38.Parent = StringValue35
- Animation38.AnimationId = "http://www.roblox.com/asset/?id=180435792"
- NumberValue39.Name = "Weight"
- NumberValue39.Parent = Animation38
- NumberValue39.Value = 1
- StringValue40.Name = "jump"
- StringValue40.Parent = Script30
- Animation41.Name = "JumpAnim"
- Animation41.Parent = StringValue40
- Animation41.AnimationId = "http://www.roblox.com/asset/?id=125750702"
- StringValue42.Name = "run"
- StringValue42.Parent = Script30
- Animation43.Name = "RunAnim"
- Animation43.Parent = StringValue42
- Animation43.AnimationId = "http://www.roblox.com/asset/?id=180426354"
- StringValue44.Name = "sit"
- StringValue44.Parent = Script30
- Animation45.Name = "SitAnim"
- Animation45.Parent = StringValue44
- Animation45.AnimationId = "http://www.roblox.com/asset/?id=178130996"
- StringValue46.Name = "toolnone"
- StringValue46.Parent = Script30
- Animation47.Name = "ToolNoneAnim"
- Animation47.Parent = StringValue46
- Animation47.AnimationId = "http://www.roblox.com/asset/?id=182393478"
- StringValue48.Name = "walk"
- StringValue48.Parent = Script30
- Animation49.Name = "WalkAnim"
- Animation49.Parent = StringValue48
- Animation49.AnimationId = "http://www.roblox.com/asset/?id=180426354"
- Camera50.Name = "ThumbnailCamera"
- Camera50.Parent = Model0
- Camera50.CFrame = CFrame.new(-120.427315, 8.9444809, -67.5636902, 0.6640172, 0.0586584844, -0.745412886, 3.7252903e-09, 0.996918142, 0.0784500837, 0.747717321, -0.0520922095, 0.661970794)
- Camera50.CoordinateFrame = CFrame.new(-120.427315, 8.9444809, -67.5636902, 0.6640172, 0.0586584844, -0.745412886, 3.7252903e-09, 0.996918142, 0.0784500837, 0.747717321, -0.0520922095, 0.661970794)
- Camera50.Focus = CFrame.new(-118.936478, 8.78757954, -68.8876419, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Camera50.focus = CFrame.new(-118.936478, 8.78757954, -68.8876419, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Pants51.Name = "Pants"
- Pants51.Parent = Model0
- Pants51.PantsTemplate = "rbxassetid://949284975"
- Shirt52.Name = "Shirt"
- Shirt52.Parent = Model0
- Shirt52.ShirtTemplate = "rbxassetid://573188703"
- Folder53.Name = "[1] Global Background Music"
- Folder53.Parent = Model0
- Sound54.Parent = Folder53
- Sound54.EmitterSize = 0
- Sound54.MinDistance = 0
- Sound54.SoundId = "rbxassetid://321451733"
- Sound54.Volume = 0.44999998807907
- Script55.Name = "**README / INSTRUCTIONS**"
- Script55.Parent = Folder53
- table.insert(cors,sandbox(Script55,function()
- -- Cindering
- -- Twitter: @Cindering_
- --[[
- Hey there! This model gives you the tools to easily set up background music in your game. You can set up global background music (music that simply plays for everyone in the game), zone-specific background music (tracks that only play when you enter a certain area), or both!
- This script contains instructions for both methods of adding background music.
- CONTENTS:
- I. Global Background Music (SIMPLE SETUP)
- II. Zone-Specific Background Music
- a. How Background Music Zones Work
- b. Setting Up Music Zones
- ------------------------------------------------------
- I. Global Background Music (SIMPLE SETUP)
- ------------------------------------------------------
- If you just want to quickly add a piece of global background music to your entire game, then all you have to do is follow these simple steps:
- 1. Go onto the ROBLOX site and find the Audio you wish to use.
- (( You can search for audio via the Develop Library: https://www.roblox.com/develop/library?CatalogContext=DevelopOnly&Category=Audio ))
- 2. Once you're on the desired Audio asset's page, copy the numeric ID you see at the end of the URL (website address bar).
- (( For example, if you want to use this audio in your game: https://www.roblox.com/Audio-Name-Here-item?id=214852782
- ...then you copy the ID, which is 214852782. ))
- 3. Inside of this model, you will see a folder named "Global Background Music" which contains a Sound object. Click on the Sound, and then in the Properties menu, paste your Audio's ID into the SoundId property and press Enter. The SoundId property should now be filled in as "rbxassetid://AUDIO_ID_HERE".
- And that's it! The music you've selected will now be played for everyone in your game. If you want, you can add multiple Sound objects to that folder to create a shuffled playlist of background music. (Tip: You can select the Sound object and press Ctrl + D to duplicate it, then change the SoundId of the new one.) You can also adjust the volume of the music (or even the pitch!) for more control.
- Whenever the game runs, the toolkit's Auto-Install script will automatically move everything to the proper location and delete any unnecessary leftovers. You don't have to do anything else!
- ------------------------------------------------------
- II. Zone-Specific Background Music
- ------------------------------------------------------
- Set up specific areas for certain music tracks to play in. Want to select one song that plays in the outdoors, and another song that plays in a specific building? Set this all up with ease.
- -----------------------------------------
- 2a. How Background Music Zones Work:
- -----------------------------------------
- A Music Zone is a model contained within the Background Music Zones folder.
- The part(s) placed inside one of those models represent the physical space in which the zone's music will be played.
- Simply put, players who walk inside of that zone's parts will hear the music that you have selected for that zone.
- Each zone contains the following objects:
- -- Music (Folder): This folder contains the Sound object(s) which will be used as music for that zone. If you only have one Sound object in there, that will be used as the sole music track for that zone. Otherwise, multiple Sound objects will allow for a shuffled playlist of music.
- -- Parts: The parts inside of the zone represent the physical area in which the zone's music will be played, as explained above. You may use multiple parts for each zone.
- -- Priority (IntValue): Priority determines which zone's music will be played when a player is standing inside of multiple overlapping zones.
- If a player moves into an overlapping zone of...
- - EQUAL OR LOWER PRIORITY: the current music will continue to play.
- - HIGHER PRIORITY: the new zone's music will start playing immediately.
- This is useful if, for example, you have a small building that you want to play unique music inside of, but the building overlaps with another larger music zone. Set the Priority of the building's music zone to be higher.
- You are allowed to create as many different music zones as you want.
- ****PERFORMANCE WITH ROTATED ZONE PARTS****
- For optimal script performance, it is recommended that you do not rotate music zones' parts at any non-90 degree increments.
- If you place the zone parts with irregular rotations, this forces the script to use the more expensive GetTouchingParts() function to determine if the character is inside of that specific part. It will still work, but it may create some lag if you do this a lot in areas with many parts.
- Whereas if you just have zone parts placed at regular 90 degree rotation increments, the script will be able to use simple, inexpensive position comparisons on the character.
- -----------------------------------------
- 2b. Setting Up Music Zones
- -----------------------------------------
- Now that you know how they work, here are the basic steps for setting up background music zones:
- 1. Create a Model which contains all of the necessary components for a zone (an IntValue named "Priority", a Folder named "Music", and Parts that will represent the physical area of the zone) in the Background Music Zones folder. Give the model a unique name.
- Tip: You may select the "Test Zone" and press Ctrl + D to easily duplicate the necessary components.
- 2. Insert Part(s) inside of this model, and move + resize them to fill the area in which you want this zone's music to be played.
- Parts are allowed to overlap, even with parts of different music zones (which is when the Priority settings come into play).
- Color coding each zone is highly recommended.
- 3. Inside the zone's Music folder, create a Sound object to use as the music track for that zone. Copy your desired Audio ID (the number at the end of the Audio page's URL) and paste it into the Sound object's SoundId property. The value should then look like "rbxassetid://AUDIO_ID_HERE". You can also adjust the Volume or the Pitch if necessary.
- (As explained in the above section, you can place multiple Sound objects into the Music folder to create a shuffled playlist.)
- 4. Ensure that the zone's Priority is set to the desired value.
- (As explained in the above section, Priority determines which music will play if a player is standing inside of two overlapping music zones. Zones with higher Priority take precedence over others.)
- 5. Repeat steps 1-4 for each new music zone that you wish to create.
- 6. Once you are done editing all of your music zones, you can drag the entire "Background Music Zones" Folder into ReplicatedStorage so that the zone parts don't get in the way of your building. (You can always move the folder back into the Workspace if you need to make edits in the future)
- (You also can paste this line into Studio's Command Bar to move the folder to ReplicatedStorage):
- workspace["Cindering's Background Music Toolkit"]["[2] Background Music Zones"].Parent = game.ReplicatedStorage
- (And to move it back into this toolkit):
- game.ReplicatedStorage["[2] Background Music Zones"].Parent = workspace["Cindering's Background Music Toolkit"]
- 7. Open the "Settings" ModuleScript in the toolkit. Set settings.UseMusicZones to true. If you don't want to use Global Background Music, set settings.UseGlobalBackgroundMusic to false. Make any other settings adjustments that you'd like.
- And you're done! You will now have unique music tracks playing in each of the different areas in your game. Whenever the game runs, the toolkit's Auto-Install script will automatically move everything to the proper location and delete any unnecessary leftovers from this toolkit.
- Thanks for using my background music toolkit! I hope this has helped ease the process of adding background music to your game.
- -- Cindering
- -- Twitter: @Cindering_
- --]]
- end))
- Script56.Name = "Auto-Install"
- Script56.Parent = Folder53
- table.insert(cors,sandbox(Script56,function()
- -- Cindering
- -- Twitter: @Cindering_
- --[[
- When the game is run, this script automatically places all of the model's contents into the correct locations and deletes any leftover clutter.
- All you have to do is configure the music IDs and/or zones as described in the README - the rest will be automatically handled!
- --]]
- local settings = require(script.Parent.Settings)
- if settings.UseGlobalBackgroundMusic == false and settings.UseMusicZones == false then
- error("Cindering's BGM error: You have disabled both Global Background Music and Music Zones. You must change at least one of these settings to 'true'.")
- return
- end
- local name1 = "[1] Global Background Music"
- local name2 = "[2] Background Music Zones"
- local container = Instance.new("Folder")
- container.Name = "CinderingBGM"
- script.Parent.Settings.Parent = container
- script.LocalBackgroundMusic.Parent = game.StarterPlayer.StarterPlayerScripts
- local music = Instance.new("Folder")
- local zones = Instance.new("Folder",music)
- zones.Name = "MusicZones"
- local global = Instance.new("Folder",music)
- global.Name = "GlobalMusic"
- if settings.UseMusicZones == true then
- local folder = script.Parent:FindFirstChild(name2) or game.ReplicatedStorage:FindFirstChild(name2) or workspace:FindFirstChild(name2) or game:FindFirstChild(name2,true) -- never know where someone might accidentally drag that folder...
- if folder then
- for _,model in pairs(folder:GetChildren()) do
- if (model:IsA("Model") and model:FindFirstChild("Music")) then
- model.Parent = zones
- end
- end
- else
- error("Cindering's BGM error: Your background music zones folder could not be found! You may have deleted/renamed the original folder. It should be named: "..name2)
- return
- end
- end
- if settings.UseGlobalBackgroundMusic == true then
- local folder = script.Parent:FindFirstChild(name1) or game.ReplicatedStorage:FindFirstChild(name1) or workspace:FindFirstChild(name1) or game:FindFirstChild(name1,true)
- if folder then
- for _,v in pairs(folder:GetChildren()) do
- if v:IsA("Sound") then
- v.Parent = global
- end
- end
- else
- error("Cindering's BGM error: Your global background music folder could not be found! You may have deleted/renamed the original folder. It should be named: "..name1)
- return
- end
- end
- if settings.UseGlobalBackgroundMusic == true and #global:GetChildren() == 0 then
- warn("Cindering's BGM warning: Your global background music folder is completely empty; no music will be played from there.")
- end
- if settings.UseMusicZones == true and #zones:GetChildren() == 0 then
- warn("Cindering's BGM warning: Your background music zones folder is completely empty; no music will be played from there.")
- end
- music.Name = "MusicFolder"
- music.Parent = container
- local count = 0
- function recurse(instance)
- for _,v in pairs(instance:GetChildren()) do
- count = count + 1
- recurse(v)
- end
- end
- recurse(music)
- local val = Instance.new("IntValue",container)
- val.Name = "ObjectCount"
- val.Value = count
- container.Parent = game.ReplicatedStorage
- script.Parent:Destroy()
- end))
- LocalScript57.Name = "LocalBackgroundMusic"
- LocalScript57.Parent = Script56
- table.insert(cors,sandbox(LocalScript57,function()
- -- Cindering
- -- Twitter: @Cindering_
- -- This script gets placed into StarterPlayerScripts where it will locally play the background music for each player.
- local plr = game.Players.LocalPlayer
- local char
- local torso
- local container = game.ReplicatedStorage:WaitForChild("CinderingBGM")
- local settings = require(container:WaitForChild("Settings"))
- local musicfolder = container:WaitForChild("MusicFolder")
- local globalfolder = musicfolder:WaitForChild("GlobalMusic")
- local zonesfolder = musicfolder:WaitForChild("MusicZones")
- local servercount = container:WaitForChild("ObjectCount").Value
- function GetMatchingCount() --objects can take some time to actually replicate to the client. make sure that the client sees the correct # of objects in the music folder before initializing the rest of the script
- local count = 0
- local function recurse(instance)
- for _,v in pairs(instance:GetChildren()) do
- count = count + 1
- recurse(v)
- end
- end
- recurse(musicfolder)
- if count == servercount then return true end
- end
- while not GetMatchingCount() do
- wait(.5)
- end
- function IsCleanRotation(v3values) --check to see whether the rotation is at clean 90 degree increments so we can use the more simplistic calculations for it
- for _,v in pairs(v3values) do
- if not (v%90 <= 0.01 or v%90 >= 89.99) then --why not just check for (v%90 == 0)? because rotations can suffer from floating point inaccuracies
- return false
- end
- end
- return true
- end
- --now, load the zone & music data into the script
- local zones = {}
- local music = {}
- local globali
- if settings.UseMusicZones == true then
- for i,zone in pairs(zonesfolder:GetChildren()) do
- if zone:IsA("Model") and zone:FindFirstChild("Music") then
- music[i] = {}
- for _,sound in pairs(zone.Music:GetChildren()) do --save all of the music data for this zone
- if sound:IsA("Sound") then
- table.insert(music[i], {["SoundId"] = sound.SoundId, ["Volume"] = sound.Volume, ["Pitch"] = sound.Pitch})
- end
- end
- zones[i] = {
- ["Priority"] = zone:FindFirstChild("Priority") and zone.Priority.Value or 1,
- ["Parts"] = {},
- ["Music"] = music[i]
- }
- for _,part in pairs(zone:GetChildren()) do
- if part:IsA("Part") then
- if IsCleanRotation({part.Rotation.X,part.Rotation.Y,part.Rotation.Z}) == true then --store the min and max X/Y/Z position coordinates of this part
- local lx,ly,lz = math.huge,math.huge,math.huge
- local mx,my,mz = -math.huge,-math.huge,-math.huge
- local function ApplyValues(p)
- if p.x < lx then lx = p.x end
- if p.x > mx then mx = p.x end
- if p.y < ly then ly = p.y end
- if p.y > my then my = p.y end
- if p.z < lz then lz = p.z end
- if p.z > mz then mz = p.z end
- end
- local points = {}
- --a bunch of sloppy math stuff to calculate the coordinates on each of the part's faces so we can figure out the min and max values. mathematicians, pls don't kill me if i'm doing this terribly
- local cf1 = part.CFrame
- local cf2 = (part.CFrame * CFrame.Angles(0,math.pi/2,0))
- local cf3 = (part.CFrame * CFrame.Angles(math.pi/2,0,0))
- local lvz = (cf1.lookVector * (part.Size.Z/2))
- local lvx = (cf2.lookVector * (part.Size.X/2))
- local lvy = (cf3.lookVector * (part.Size.Y/2))
- points[1] = cf1+lvz
- points[2] = cf1-lvz
- points[3] = cf2+lvx
- points[4] = cf2-lvx
- points[5] = cf3+lvy
- points[6] = cf3-lvy
- for _,p in pairs(points) do
- ApplyValues(p)
- end
- table.insert(zones[i]["Parts"],{["Coordinates"] = {lx=lx,ly=ly,lz=lz, mx=mx,my=my,mz=mz}})
- else --save a reference to the part itself to be used for GetTouchingParts(), since it has a complex rotation that can't be solved with my own feeble calculations
- table.insert(zones[i]["Parts"],{["Part"] = part})
- end
- end
- end
- end
- end
- end
- if settings.UseGlobalBackgroundMusic == true then
- globali = #music + 1
- music[globali] = {}
- for _,sound in pairs(globalfolder:GetChildren()) do
- if sound:IsA("Sound") then
- table.insert(music[globali], {["SoundId"] = sound.SoundId, ["Volume"] = sound.Volume, ["Pitch"] = sound.Pitch})
- end
- end
- end
- --end this enormous, disgusting block of code
- --mute button stuff
- local canmute = settings.DisplayMuteButton
- local clonegui
- if canmute then
- clonegui = script.MuteButtonGui:clone()
- end
- script.MuteButtonGui:Destroy()
- local musicon = true
- function SetButtonStyle(button)
- button.Text = "Music: ".. (musicon and "ON" or "OFF")
- button.Style = musicon and Enum.ButtonStyle.RobloxRoundDefaultButton or Enum.ButtonStyle.RobloxRoundDropdownButton
- button.TextColor3 = musicon and Color3.new(1,1,1) or Color3.new(.2,.2,.23)
- end
- function CreateButton()
- local gui = clonegui:clone()
- local button = gui.Button
- button.Visible = true
- SetButtonStyle(button)
- button.MouseButton1Click:connect(function()
- musicon = not musicon
- local bgm = script:FindFirstChild("BGM")
- if bgm then
- bgm.Volume = musicon and bgm.OriginalVolume.Value or 0
- end
- SetButtonStyle(button)
- end)
- gui.Parent = plr:WaitForChild("PlayerGui")
- end
- function CharInit()
- char = plr.Character
- torso = char:WaitForChild("HumanoidRootPart")
- if canmute then CreateButton() end
- end
- if plr.Character and plr.Character.Parent ~= nil then
- CharInit()
- end
- plr.CharacterAdded:connect(function()
- CharInit()
- end)
- --now, get to playing the music
- local FadeoutTime = settings.MusicFadeoutTime
- function PlaySound(sounddata)
- if sounddata == nil then return end
- local sound = Instance.new("Sound")
- sound.Looped = true
- sound.SoundId = sounddata.SoundId
- sound.Volume = musicon and sounddata.Volume or 0
- local v = Instance.new("NumberValue",sound)
- v.Name = "OriginalVolume"
- v.Value = sounddata.Volume
- sound.Pitch = sounddata.Pitch
- sound.Name = "BGM"
- sound.Parent = script
- sound:Play()
- end
- function FadeOutSound(sound)
- local basevol = sound.Volume
- local count = math.ceil(30*FadeoutTime)
- if count < 1 then
- count = 1
- end
- for i=1,count do
- if sound then
- sound.Volume = sound.Volume - (basevol / count)
- wait(1/30)
- end
- end
- if sound then
- sound:Stop()
- sound:Destroy()
- end
- end
- if settings.UseGlobalBackgroundMusic == true and settings.UseMusicZones == false then
- if #music[globali] == 1 then --global BGM with just 1 song? ez pz
- PlaySound(music[1][1])
- return
- elseif #music[globali] == 0 then --there's no music to play...?
- return
- end
- end
- local recentindices = {} --keeps track of recently selected indicies, so as not to play repeat music tracks
- math.randomseed(tick())
- local currentzone
- local zoneplayingmusic
- function CheckIfRecent(i)
- for _,v in pairs(recentindices) do
- if v == i then
- return true
- end
- end
- return false
- end
- function SelectRandomMusic(musiclist) --select a random number, excluding ones that were already used recently
- if musiclist == nil or #musiclist == 0 then return end
- local possiblenumbers = {}
- local selectedindex
- for i=1,#musiclist do
- if not CheckIfRecent(i) then
- table.insert(possiblenumbers,i)
- end
- end
- local selectedindex = possiblenumbers[math.random(1,#possiblenumbers)]
- table.insert(recentindices,selectedindex)
- if #recentindices > math.ceil(#musiclist / 2) then
- table.remove(recentindices,1)
- end
- return musiclist[selectedindex]
- end
- function IsInZone(zonedata)
- if torso and torso.Parent ~= nil then
- local p = torso.Position
- for _,data in pairs(zonedata["Parts"]) do
- if data["Coordinates"] then
- local t = data["Coordinates"]
- if (p.x > t.lx and p.x < t.mx and p.y > t.ly and p.y < t.my and p.z > t.lz and p.z < t.mz) then --is the character within all the coordinates of the zone?
- return true
- end
- elseif data["Part"] then --complex part? create a clone of the part and check if it's touching the character's torso
- local part = data["Part"]:clone()
- part.Anchored = true
- part.Parent = workspace.CurrentCamera or workspace
- part.CanCollide = true
- local touching = part:GetTouchingParts()
- part:Destroy()
- for _,v in pairs(touching) do
- if v == torso then
- return true
- end
- end
- end
- end
- return false
- end
- end
- function CalculateCurrentZone()
- local priority = -math.huge
- local oldzone = currentzone
- local selectedzone
- if currentzone then
- if IsInZone(currentzone) then
- selectedzone = currentzone
- priority = currentzone["Priority"]
- end
- end
- for _,zone in pairs(zones) do
- if zone["Priority"] > priority and IsInZone(zone) then
- priority = zone["Priority"]
- selectedzone = zone
- end
- end
- currentzone = selectedzone
- if currentzone ~= oldzone and (currentzone ~= nil or settings.UseGlobalBackgroundMusic == true) then
- recentindices = {}
- end
- return currentzone,oldzone
- end
- function RunCycle() --the main cycle which will continuously run, checking which zones (if any) the character is in and playing new music when necessary
- local bgm = script:FindFirstChild("BGM")
- if settings.UseMusicZones == true then
- local zone,oldzone = CalculateCurrentZone()
- if zone ~= oldzone and zone ~= zoneplayingmusic and bgm then
- if (zone == nil and (settings.UseGlobalBackgroundMusic == true or settings.MusicOnlyPlaysWithinZones == true)) or zone ~= nil then
- FadeOutSound(bgm)
- return
- end
- elseif zone and bgm == nil then
- PlaySound(SelectRandomMusic(zone["Music"]))
- zoneplayingmusic = zone
- return
- elseif zone == nil and oldzone and settings.MusicOnlyPlaysWithinZones == false and settings.UseGlobalBackgroundMusic == false and bgm == nil then
- PlaySound(SelectRandomMusic(oldzone["Music"]))
- zoneplayingmusic = oldzone
- return
- elseif zoneplayingmusic and settings.MusicOnlyPlaysWithinZones == false and settings.UseGlobalBackgroundMusic == false and bgm == nil then
- PlaySound(SelectRandomMusic(zoneplayingmusic["Music"]))
- return
- elseif settings.UseGlobalBackgroundMusic == true and bgm == nil then
- PlaySound(SelectRandomMusic(music[globali]))
- zoneplayingmusic = nil
- return
- end
- elseif bgm == nil and settings.UseGlobalBackgroundMusic == true then
- PlaySound(SelectRandomMusic(music[globali]))
- return
- end
- if bgm and (settings.UseGlobalBackgroundMusic == true and zoneplayingmusic == nil and #music[globali] > 1) or (zoneplayingmusic and #zoneplayingmusic["Music"] > 1) then
- local length = bgm.TimeLength
- local pos = bgm.TimePosition
- if length ~= 0 and length - pos < FadeoutTime + .5 then
- FadeOutSound(bgm)
- end
- end
- end
- while wait(.5) do
- RunCycle()
- end
- -- Cindering
- -- Twitter: @Cindering_
- end))
- ScreenGui58.Name = "MuteButtonGui"
- ScreenGui58.Parent = LocalScript57
- TextButton59.Name = "Button"
- TextButton59.Parent = ScreenGui58
- TextButton59.Position = UDim2.new(1, -92, 1, -37)
- TextButton59.Size = UDim2.new(0, 90, 0, 35)
- TextButton59.BackgroundColor = BrickColor.new("Institutional white")
- TextButton59.BackgroundColor3 = Color3.new(1, 1, 1)
- TextButton59.Style = Enum.ButtonStyle.RobloxRoundDropdownButton
- TextButton59.Font = Enum.Font.SourceSansBold
- TextButton59.FontSize = Enum.FontSize.Size18
- TextButton59.Text = "Music: ON"
- TextButton59.TextColor = BrickColor.new("Earth blue")
- TextButton59.TextColor3 = Color3.new(0.231373, 0.231373, 0.278431)
- TextButton59.TextSize = 18
- TextButton59.TextStrokeColor3 = Color3.new(0.156863, 0.160784, 0.176471)
- ModuleScript60.Name = "Settings"
- ModuleScript60.Parent = Folder53
- table.insert(cors,sandbox(ModuleScript60,function()
- -- Looking for how exactly to set up your background music? Open the Readme/Instructions script!
- local settings = {}
- settings.UseGlobalBackgroundMusic = true -- If you want to play Global Background Music for everyone in your game, set this to true.
- settings.UseMusicZones = false -- If you are using the Background Music Zones to play specific music in certain areas, set this to true.
- -- You may turn both of these on at once. In that case, zone-specific music will play in the appropriate zones, and global background music will play whenever you're not within any zone.
- settings.DisplayMuteButton = true -- If set to true, there will be a button in the bottom-right corner of the screen allowing players to mute the background music.
- settings.MusicFadeoutTime = 2 -- How long music takes to fade out, in seconds.
- settings.MusicOnlyPlaysWithinZones = false -- (This setting only applies when UseGlobalBackgroundMusic is set to false) If a player walks into an area that's not covered by any music zone, what should happen? If true, music will stop playing. If false, the music from the previous zone will continue to play.
- return settings
- end))
- for i,v in pairs(mas:GetChildren()) do
- v.Parent = script
- pcall(function() v:MakeJoints() end)
- end
- mas:Destroy()
- for i,v in pairs(cors) do
- spawn(function()
- pcall(v)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment