Advertisement
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"))
- Tool0 = Instance.new("Tool")
- Part1 = Instance.new("Part")
- Model2 = Instance.new("Model")
- Part3 = Instance.new("Part")
- SpecialMesh4 = Instance.new("SpecialMesh")
- Motor6D5 = Instance.new("Motor6D")
- Motor6D6 = Instance.new("Motor6D")
- Sound7 = Instance.new("Sound")
- Sound8 = Instance.new("Sound")
- Sound9 = Instance.new("Sound")
- Sound10 = Instance.new("Sound")
- Part11 = Instance.new("Part")
- SpecialMesh12 = Instance.new("SpecialMesh")
- Part13 = Instance.new("Part")
- SpecialMesh14 = Instance.new("SpecialMesh")
- Sound15 = Instance.new("Sound")
- Sound16 = Instance.new("Sound")
- Part17 = Instance.new("Part")
- SpecialMesh18 = Instance.new("SpecialMesh")
- Weld19 = Instance.new("Weld")
- Weld20 = Instance.new("Weld")
- LocalScript21 = Instance.new("LocalScript")
- Animation22 = Instance.new("Animation")
- Tool0.Name = "BatCloak"
- Tool0.Parent = mas
- Tool0.TextureId = "http://www.roblox.com/asset/?id=94819016"
- Tool0.GripPos = Vector3.new(0, 0, 0.200000003)
- Tool0.ToolTip = "Double jump to turn into a bat!"
- Tool0.CanBeDropped = false
- Part1.Name = "Handle"
- Part1.Parent = Tool0
- Part1.Transparency = 1
- Part1.Rotation = Vector3.new(-180, 0, -180)
- Part1.CanCollide = false
- Part1.FormFactor = Enum.FormFactor.Custom
- Part1.Size = Vector3.new(0.200000003, 0.200000003, 0.200000003)
- Part1.CFrame = CFrame.new(0, 3.00000072, 0, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- Part1.Position = Vector3.new(0, 3.00000072, 0)
- Part1.Orientation = Vector3.new(0, 180, 0)
- Model2.Name = "Bat"
- Model2.Parent = Part1
- Part3.Name = "Body"
- Part3.Parent = Model2
- Part3.Rotation = Vector3.new(-180, 0, -180)
- Part3.CanCollide = false
- Part3.Locked = true
- Part3.FormFactor = Enum.FormFactor.Custom
- Part3.Size = Vector3.new(0.519999981, 1.75, 0.610000014)
- Part3.CFrame = CFrame.new(0, 3.00000072, 0, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- Part3.BottomSurface = Enum.SurfaceType.Smooth
- Part3.TopSurface = Enum.SurfaceType.Smooth
- Part3.Position = Vector3.new(0, 3.00000072, 0)
- Part3.Orientation = Vector3.new(0, 180, 0)
- SpecialMesh4.Parent = Part3
- SpecialMesh4.MeshId = "http://www.roblox.com/asset/?id=94821092"
- SpecialMesh4.TextureId = "http://www.roblox.com/asset/?id=94820224"
- SpecialMesh4.MeshType = Enum.MeshType.FileMesh
- Motor6D5.Name = "Left Shoulder"
- Motor6D5.Parent = Part3
- Motor6D5.C0 = CFrame.new(-0.0822467804, 0.312738031, 0.114303589, 1, 0, 0, 0, -4.37113883e-08, -1, 0, 1, -4.37113883e-08)
- Motor6D5.C1 = CFrame.new(1.125, 0.349999994, 0, 1, 0, 0, 0, -4.37113883e-08, -1, 0, 1, -4.37113883e-08)
- Motor6D5.Part0 = Part3
- Motor6D5.Part1 = Part11
- Motor6D5.MaxVelocity = 0.5
- Motor6D6.Name = "Right Shoulder"
- Motor6D6.Parent = Part3
- Motor6D6.C0 = CFrame.new(0.0820000172, 0.312998861, 0.109996796, 1, 0, 0, 0, -4.37113883e-08, 1, 0, -1, -4.37113883e-08)
- Motor6D6.C1 = CFrame.new(-1.125, 0.349999994, 0, 1, 0, 0, 0, -4.37113883e-08, 1, 0, -1, -4.37113883e-08)
- Motor6D6.Part0 = Part3
- Motor6D6.Part1 = Part13
- Motor6D6.MaxVelocity = 0.5
- Sound7.Name = "Squeak1"
- Sound7.Parent = Part3
- Sound7.SoundId = "http://www.roblox.com/asset/?id=94899284"
- Sound7.Volume = 1
- Sound8.Name = "Squeak2"
- Sound8.Parent = Part3
- Sound8.SoundId = "http://www.roblox.com/asset/?id=94888905"
- Sound8.Volume = 1
- Sound9.Name = "Squeak3"
- Sound9.Parent = Part3
- Sound9.SoundId = "http://www.roblox.com/asset/?id=94888934"
- Sound9.Volume = 1
- Sound10.Name = "WindSqueak"
- Sound10.Parent = Part3
- Sound10.SoundId = "http://www.roblox.com/asset/?id=94889839"
- Sound10.Volume = 1
- Part11.Name = "Left Wing"
- Part11.Parent = Model2
- Part11.Rotation = Vector3.new(-180, 0, -180)
- Part11.CanCollide = false
- Part11.Locked = true
- Part11.FormFactor = Enum.FormFactor.Custom
- Part11.Size = Vector3.new(2.25, 1.57000005, 0.200000003)
- Part11.CFrame = CFrame.new(1.20724678, 2.96273875, -0.114303589, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- Part11.BottomSurface = Enum.SurfaceType.Smooth
- Part11.TopSurface = Enum.SurfaceType.Smooth
- Part11.Position = Vector3.new(1.20724678, 2.96273875, -0.114303589)
- Part11.Orientation = Vector3.new(0, 180, 0)
- SpecialMesh12.Parent = Part11
- SpecialMesh12.MeshId = "http://www.roblox.com/asset/?id=94821113"
- SpecialMesh12.TextureId = "http://www.roblox.com/asset/?id=94820224"
- SpecialMesh12.MeshType = Enum.MeshType.FileMesh
- Part13.Name = "Right Wing"
- Part13.Parent = Model2
- Part13.Rotation = Vector3.new(-180, 0, -180)
- Part13.CanCollide = false
- Part13.Locked = true
- Part13.FormFactor = Enum.FormFactor.Custom
- Part13.Size = Vector3.new(2.25, 1.57000005, 0.200000003)
- Part13.CFrame = CFrame.new(-1.20700002, 2.96299958, -0.109996796, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- Part13.BottomSurface = Enum.SurfaceType.Smooth
- Part13.TopSurface = Enum.SurfaceType.Smooth
- Part13.Position = Vector3.new(-1.20700002, 2.96299958, -0.109996796)
- Part13.Orientation = Vector3.new(0, 180, 0)
- SpecialMesh14.Parent = Part13
- SpecialMesh14.MeshId = "http://www.roblox.com/asset/?id=94821133"
- SpecialMesh14.TextureId = "http://www.roblox.com/asset/?id=94820224"
- SpecialMesh14.MeshType = Enum.MeshType.FileMesh
- Sound15.Name = "Base"
- Sound15.Parent = Part1
- Sound15.SoundId = "http://www.roblox.com/asset/?id=94912586"
- Sound15.Volume = 1
- Sound16.Name = "WindBreath"
- Sound16.Parent = Part1
- Sound16.SoundId = "http://www.roblox.com/asset/?id=94888779"
- Sound16.Volume = 1
- Part17.Name = "Cloak"
- Part17.Parent = Part1
- Part17.Rotation = Vector3.new(-180, 0, -180)
- Part17.CanCollide = false
- Part17.Locked = true
- Part17.FormFactor = Enum.FormFactor.Custom
- Part17.Size = Vector3.new(0.200000003, 0.200000003, 0.200000003)
- Part17.CFrame = CFrame.new(1.5, 1.95384955, -2.33785152, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- Part17.BottomSurface = Enum.SurfaceType.Smooth
- Part17.TopSurface = Enum.SurfaceType.Smooth
- Part17.Position = Vector3.new(1.5, 1.95384955, -2.33785152)
- Part17.Orientation = Vector3.new(0, 180, 0)
- SpecialMesh18.Parent = Part17
- SpecialMesh18.MeshId = "http://www.roblox.com/asset/?id=94820260"
- SpecialMesh18.Scale = Vector3.new(1.5, 1.5, 1.5)
- SpecialMesh18.TextureId = "http://www.roblox.com/asset/?id=94820166"
- SpecialMesh18.MeshType = Enum.MeshType.FileMesh
- SpecialMesh18.Scale = Vector3.new(1.5, 1.5, 1.5)
- Weld19.Name = "HandleToBatBody"
- Weld19.Parent = Part1
- Weld19.Part0 = Part1
- Weld19.Part1 = Part3
- Weld20.Name = "HandleToCloak"
- Weld20.Parent = Part1
- Weld20.C0 = CFrame.new(-1.5, -1.04615116, 2.33785152, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Weld20.Part0 = Part1
- Weld20.Part1 = Part17
- LocalScript21.Name = "BatCloak"
- LocalScript21.Parent = Tool0
- table.insert(cors,sandbox(LocalScript21,function()
- -----------------
- --| Constants |--
- -----------------
- local WALK_SPEED_BUFF = 6
- local BAT_MOVE_FACTOR = 1.8
- local BAT_TOUCH_DAMAGE = 4
- local CLOAK_FLOAT_TIME = 1
- local ONE_STEP = 1/30
- local RBX_GRAVITY = 196.2
- local FAR_FAR_AWAY = Vector3.new(5e6, 5e6, 5e6)
- --------------------
- --| WaitForChild |--
- --------------------
- -- Waits for parent.child to exist, then returns it
- local function WaitForChild(parent, childName)
- assert(parent, "ERROR: WaitForChild: parent is nil")
- while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
- return parent[childName]
- end
- -----------------
- --| Variables |--
- -----------------
- local DebrisService = Game:GetService('Debris')
- local PlayersService = Game:GetService('Players')
- local LightingService = Game:GetService('Lighting') --TODO: Replace with data store service when available
- local Camera = Workspace.CurrentCamera
- local MyPlayer = PlayersService.LocalPlayer
- local Mouse = MyPlayer:GetMouse()
- local Tool = script.Parent
- local ToolHandle = Tool.Handle
- local Bat = WaitForChild(ToolHandle, 'Bat')
- Bat.Parent = LightingService -- Hide it asap to protect welds and such
- local BatBody = WaitForChild(Bat, 'Body')
- local LeftShoulderJoint = WaitForChild(BatBody, 'Left Shoulder')
- local RightShoulderJoint = WaitForChild(BatBody, 'Right Shoulder')
- local WindSqueakSound = WaitForChild(BatBody, 'WindSqueak')
- local SqueakSounds = {}
- table.insert(SqueakSounds, WaitForChild(BatBody, 'Squeak1'))
- table.insert(SqueakSounds, WaitForChild(BatBody, 'Squeak2'))
- table.insert(SqueakSounds, WaitForChild(BatBody, 'Squeak3'))
- local Cloak = WaitForChild(ToolHandle, 'Cloak')
- Cloak.Parent = LightingService -- Hide it asap to protect welds and such
- local WindBreathSound = WaitForChild(ToolHandle, 'WindBreath')
- local BaseSound = WaitForChild(ToolHandle, 'Base')
- local EquipIdleAnimation = WaitForChild(script, 'StandPerfectlyStill')
- local MyModel = nil
- local MyTorso = nil
- local LastSpaceTime = 0
- local Left = false
- local Right = false
- local Up = false
- local Down = false
- local Forward = false
- local Backward = false
- local TargetPoint = Vector3.new()
- local Flapping, Waiting, WingsDown = true, false, true
- local LastWingAngle = 0
- local CloakAntigravity = nil
- local IdleAnimTrack = nil
- local LastRandomSqueakTime = 0
- local Equipped = false
- -------------------------
- --| Utility Functions |--
- -------------------------
- -- Returns total mass of instance and all children
- local function GetMassRecursive(instance)
- local mass = 0
- if instance:IsA('BasePart') then
- mass = mass + instance:GetMass()
- end
- for _, child in pairs(instance:GetChildren()) do
- if child then
- mass = mass + GetMassRecursive(child)
- end
- end
- return mass
- end
- -- Returns true if a is within epsilon of b
- local function IsClose(a, b, epsilon)
- epsilon = epsilon or 0.01
- return (a <= b + epsilon and a >= b - epsilon)
- end
- -- Removes any old creator tags and applies new ones to the specified target
- local function ApplyTags(target)
- while target:FindFirstChild('creator') do
- target.creator:Destroy()
- end
- local creatorTag = Instance.new('ObjectValue')
- creatorTag.Value = MyPlayer
- creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
- local iconTag = Instance.new('StringValue')
- iconTag.Value = Tool.TextureId
- iconTag.Name = 'icon'
- iconTag.Parent = creatorTag
- creatorTag.Parent = target
- DebrisService:AddItem(creatorTag, 1.5)
- end
- -----------------------
- --| Other Functions |--
- -----------------------
- local function Transform()
- Camera.CameraSubject = BatBody
- Camera.CameraType = Enum.CameraType.Follow
- BatBody.CFrame = MyTorso.CFrame
- BatBody.Velocity = Vector3.new()
- Bat.Parent = Workspace
- MyModel:MoveTo(FAR_FAR_AWAY)
- MyTorso.Anchored = true
- TargetPoint = BatBody.Position
- local smoke = Instance.new('Smoke')
- Delay(0.3, function() smoke.Enabled = false end)
- DebrisService:AddItem(smoke, 5)
- smoke.Parent = BatBody
- WindSqueakSound:Play()
- end
- local function UnTransform()
- Bat.Parent = LightingService
- MyModel:MoveTo(BatBody.Position)
- MyTorso.Anchored = false
- MyTorso.Velocity = Vector3.new()
- Camera.CameraSubject = MyModel
- Camera.CameraType = Enum.CameraType.Custom
- local smoke = Instance.new('Smoke', MyTorso)
- Delay(0.3, function() smoke.Enabled = false end)
- DebrisService:AddItem(smoke, 5)
- WindBreathSound:Play()
- end
- local function OnBatPartTouched(otherPart)
- if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
- local humanoid = otherPart.Parent.Humanoid
- ApplyTags(humanoid)
- humanoid:TakeDamage(BAT_TOUCH_DAMAGE)
- end
- end
- local function Die()
- local myHumanoid = MyModel:FindFirstChild('Humanoid')
- if myHumanoid and myHumanoid.Health > 0 then
- myHumanoid.Health = 0
- end
- if Bat.Parent == Workspace then
- Bat:BreakJoints()
- BatBody.Anchored = false
- end
- DebrisService:AddItem(Bat, 2)
- DebrisService:AddItem(Cloak, 2)
- end
- local function OnPlayerRemoving(player)
- if player == MyPlayer then
- Bat:Destroy()
- Cloak:Destroy()
- end
- end
- local function OnKey(key, isDown)
- key = key:lower()
- if key == 'w' or key == '' then
- Forward = isDown
- elseif key == 's' or key == '' then
- Backward = isDown
- elseif key == 'a' or key == '' then
- Left = isDown
- elseif key == 'd' or key == '' then
- Right = isDown
- elseif key == 'e' then
- Up = isDown
- elseif key == 'q' then
- Down = isDown
- elseif key == ' ' and isDown then
- if Bat.Parent == Workspace then
- UnTransform()
- else -- Check for double jump
- local now = time()
- if now - LastSpaceTime < 0.7 and Equipped then
- Transform()
- end
- LastSpaceTime = now
- end
- end
- end
- local function OnEquipped()
- -- Initialize
- MyModel = Tool.Parent
- MyTorso = MyModel.Torso
- BatBody.Anchored = true
- -- Put on cloak
- Spawn(function() --NOTE: We have to spawn when creating welds during equip or it flips out
- Cloak.Parent = MyModel
- local weld = Instance.new('Weld', MyTorso)
- weld.Name = "CloakWeld"
- weld.Part0 = MyTorso
- weld.Part1 = Cloak
- weld.C1 = CFrame.new(0, 0.545642853, -0.638683319)
- end)
- -- Play idle animation, get buff, connect death
- local humanoid = MyModel:FindFirstChild('Humanoid')
- if humanoid then
- if not IdleAnimTrack then
- IdleAnimTrack = humanoid:LoadAnimation(EquipIdleAnimation)
- end
- IdleAnimTrack:Play()
- humanoid.WalkSpeed = humanoid.WalkSpeed + WALK_SPEED_BUFF
- humanoid.Died:connect(Die)
- end
- Equipped = true
- end
- local function OnActivated()
- if Bat.Parent ~= Workspace then -- Clicking while cloaked
- if not CloakAntigravity then
- BaseSound:Play()
- CloakAntigravity = Instance.new('BodyForce', MyTorso)
- CloakAntigravity.force = Vector3.new(0, GetMassRecursive(MyModel) * RBX_GRAVITY, 0)
- Delay(CLOAK_FLOAT_TIME, function()
- if CloakAntigravity then
- CloakAntigravity:Destroy()
- CloakAntigravity = nil
- end
- end)
- end
- end
- end
- local function OnUnequipped()
- Equipped = false
- -- Take off cloak
- Cloak.Parent = LightingService
- -- Debuff
- local humanoid = MyModel:FindFirstChild('Humanoid')
- if humanoid then
- humanoid.WalkSpeed = humanoid.WalkSpeed - WALK_SPEED_BUFF
- end
- -- Stop idle animation
- if IdleAnimTrack then
- IdleAnimTrack:Stop()
- end
- end
- --------------------
- --| Script Logic |--
- --------------------
- Tool.Equipped:connect(OnEquipped)
- Tool.Activated:connect(OnActivated)
- Tool.Unequipped:connect(OnUnequipped)
- Mouse.KeyDown:connect(function(key) OnKey(key, true) end)
- Mouse.KeyUp:connect(function(key) OnKey(key, false) end)
- PlayersService.PlayerRemoving:connect(OnPlayerRemoving)
- for _, child in pairs(Bat:GetChildren()) do
- if child:IsA('BasePart') then
- child.Touched:connect(OnBatPartTouched)
- end
- end
- while true do
- if Bat.Parent == Workspace then
- if not BatBody.Parent or not LeftShoulderJoint.Parent or not RightShoulderJoint.Parent then Die() break end
- -- Update bat angle based on camera angle
- local cameraLookVector = Camera.CoordinateFrame.lookVector
- BatBody.CFrame = CFrame.new(BatBody.Position, BatBody.Position + cameraLookVector)
- -- Update bat position based on key input
- local forwardVector = BatBody.CFrame.lookVector
- local upVector = BatBody.CFrame:vectorToWorldSpace(Vector3.new(0, 1, 0))
- local rightVector = forwardVector:Cross(upVector)
- local moveVector = Vector3.new()
- if Forward then moveVector = moveVector + forwardVector end
- if Backward then moveVector = moveVector - forwardVector end
- if Left then moveVector = moveVector - rightVector end
- if Right then moveVector = moveVector + rightVector end
- if Up then moveVector = moveVector + upVector end
- if Down then moveVector = moveVector - upVector end
- TargetPoint = TargetPoint + (moveVector * BAT_MOVE_FACTOR)
- BatBody.CFrame = BatBody.CFrame - BatBody.Position + BatBody.Position:Lerp(TargetPoint, 0.25)
- if Flapping then -- Update wings
- if not Waiting then
- local angle = WingsDown and 0.5 or -0.4
- LeftShoulderJoint.DesiredAngle = angle
- RightShoulderJoint.DesiredAngle = angle
- LastWingAngle = angle
- Waiting = true
- else -- Waiting for wings to reach desired angle
- if IsClose(LeftShoulderJoint.CurrentAngle, LastWingAngle) or IsClose(RightShoulderJoint.CurrentAngle, LastWingAngle) then
- WingsDown = not WingsDown
- Waiting = false
- end
- end
- end
- -- Play squeak sounds randomly
- local now = time()
- if now - LastRandomSqueakTime > 1 and math.random() < 0.1 then
- local i = math.random(1, #SqueakSounds)
- SqueakSounds[i]:Play()
- LastRandomSqueakTime = now
- end
- end
- wait(ONE_STEP)
- end
- end))
- Animation22.Name = "StandPerfectlyStill"
- Animation22.Parent = LocalScript21
- Animation22.AnimationId = "http://www.roblox.com/Asset?ID=94853940"
- for i,v in pairs(mas:GetChildren()) do
- v.Parent = game:GetService("Players").LocalPlayer.Backpack
- 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
Advertisement