Advertisement
lllkkklkk

sonic V2

Jul 29th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. -- LocalScript in StarterPlayerScripts
  2.  
  3. local Players = game:GetService("Players")
  4. local UserInputService = game:GetService("UserInputService")
  5. local RunService = game:GetService("RunService")
  6. local Debris = game:GetService("Debris")
  7.  
  8. local player = Players.LocalPlayer
  9. local character = player.Character or player.CharacterAdded:Wait()
  10. local humanoid = character:WaitForChild("Humanoid")
  11. local terrain = workspace.Terrain
  12.  
  13. -- Animation IDs
  14. local idleAnimationId = "rbxassetid://18622529913"
  15. local sprintAnimationId = "rbxassetid://2"
  16.  
  17. -- Speeds
  18. local walkSpeed = 34
  19. local sprintSpeed = 60
  20.  
  21. -- Double Jump variables
  22. local canDoubleJump = true
  23. local doubleJumpCooldown = 1
  24. local lastJumpTime = 0
  25.  
  26. -- Load animations
  27. local idleAnimation = Instance.new("Animation")
  28. idleAnimation.AnimationId = idleAnimationId
  29. local idleTrack = humanoid:LoadAnimation(idleAnimation)
  30.  
  31. local sprintAnimation = Instance.new("Animation")
  32. sprintAnimation.AnimationId = sprintAnimationId
  33. local sprintTrack = humanoid:LoadAnimation(sprintAnimation)
  34.  
  35. -- Set idle animation: Play the idle animation when the player is not moving
  36. humanoid.Running:Connect(function(speed)
  37. if speed < 0.1 then
  38. if not idleTrack.IsPlaying then
  39. idleTrack:Play()
  40. end
  41. else
  42. if idleTrack.IsPlaying then
  43. idleTrack:Stop()
  44. end
  45. end
  46. end)
  47.  
  48. -- Handle sprinting: Toggle sprint on and off
  49. local sprinting = false
  50.  
  51. local function toggleSprint(isSprinting)
  52. if isSprinting then
  53. humanoid.WalkSpeed = sprintSpeed
  54. sprintTrack:Play()
  55. else
  56. humanoid.WalkSpeed = walkSpeed
  57. sprintTrack:Stop()
  58. end
  59. sprinting = isSprinting
  60. end
  61.  
  62. UserInputService.InputBegan:Connect(function(input)
  63. if input.KeyCode == Enum.KeyCode.LeftShift then
  64. toggleSprint(true)
  65. elseif input.KeyCode == Enum.KeyCode.Space then
  66. -- Double Jump handling
  67. local currentTime = tick()
  68. if humanoid:GetState() == Enum.HumanoidStateType.Freefall and canDoubleJump and (currentTime - lastJumpTime > doubleJumpCooldown) then
  69. canDoubleJump = false
  70. lastJumpTime = currentTime
  71.  
  72. -- Move the character forward instead of upward
  73. local forwardDirection = character.HumanoidRootPart.CFrame.lookVector * 50
  74. character.HumanoidRootPart.Velocity = Vector3.new(forwardDirection.X, 0, forwardDirection.Z)
  75.  
  76. -- Reset double jump after cooldown
  77. task.delay(doubleJumpCooldown, function()
  78. canDoubleJump = true
  79. end)
  80. end
  81. end
  82. end)
  83.  
  84. UserInputService.InputEnded:Connect(function(input)
  85. if input.KeyCode == Enum.KeyCode.LeftShift then
  86. toggleSprint(false)
  87. end
  88. end)
  89.  
  90. -- Set initial walk speed
  91. humanoid.WalkSpeed = walkSpeed
  92.  
  93. -- Check for water terrain and place part: Create a platform if the player is sprinting over water
  94. RunService.RenderStepped:Connect(function()
  95. if sprinting then
  96. local ray = Ray.new(character.HumanoidRootPart.Position, Vector3.new(0, -5, 0))
  97. local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {character})
  98. if part and part:IsA("Terrain") and terrain:ReadVoxels(Region3.new(position - Vector3.new(2, 2, 2), position + Vector3.new(2, 2, 2)), 4)[1][1][1] == Enum.Material.Water then
  99. local waterPart = Instance.new("Part")
  100. waterPart.Size = Vector3.new(5, 1, 5)
  101. waterPart.Anchored = true
  102. waterPart.CanCollide = true
  103. waterPart.Transparency = 0.5
  104. waterPart.Position = position + Vector3.new(0, -1, 0)
  105. waterPart.Parent = workspace
  106.  
  107. -- Remove the part after a short delay
  108. Debris:AddItem(waterPart, 0.1)
  109. end
  110. end
  111. end)
  112.  
  113. -- Change body part colors: Set the character's arms to tan, legs to blue, and torso to tan
  114. local function setBodyColors()
  115. local function changeColor(partName, color)
  116. local part = character:FindFirstChild(partName)
  117. if part then
  118. part.BrickColor = BrickColor.new(color)
  119. end
  120. end
  121.  
  122. changeColor("LeftArm", "Tan")
  123. changeColor("RightArm", "Tan")
  124. changeColor("LeftLeg", "Bright blue")
  125. changeColor("RightLeg", "Bright blue")
  126. changeColor("Torso", "Tan")
  127. end
  128.  
  129. -- Set colors on character load: Apply colors when the character is loaded or respawned
  130. if character then
  131. setBodyColors()
  132. end
  133.  
  134. player.CharacterAdded:Connect(function(newCharacter)
  135. character = newCharacter
  136. humanoid = character:WaitForChild("Humanoid")
  137. setBodyColors()
  138. end)
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement