Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LocalScript in StarterPlayerScripts
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Debris = game:GetService("Debris")
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local terrain = workspace.Terrain
- -- Animation IDs
- local idleAnimationId = "rbxassetid://18622529913"
- local sprintAnimationId = "rbxassetid://2"
- -- Speeds
- local walkSpeed = 34
- local sprintSpeed = 60
- -- Double Jump variables
- local canDoubleJump = true
- local doubleJumpCooldown = 1
- local lastJumpTime = 0
- -- Load animations
- local idleAnimation = Instance.new("Animation")
- idleAnimation.AnimationId = idleAnimationId
- local idleTrack = humanoid:LoadAnimation(idleAnimation)
- local sprintAnimation = Instance.new("Animation")
- sprintAnimation.AnimationId = sprintAnimationId
- local sprintTrack = humanoid:LoadAnimation(sprintAnimation)
- -- Set idle animation: Play the idle animation when the player is not moving
- humanoid.Running:Connect(function(speed)
- if speed < 0.1 then
- if not idleTrack.IsPlaying then
- idleTrack:Play()
- end
- else
- if idleTrack.IsPlaying then
- idleTrack:Stop()
- end
- end
- end)
- -- Handle sprinting: Toggle sprint on and off
- local sprinting = false
- local function toggleSprint(isSprinting)
- if isSprinting then
- humanoid.WalkSpeed = sprintSpeed
- sprintTrack:Play()
- else
- humanoid.WalkSpeed = walkSpeed
- sprintTrack:Stop()
- end
- sprinting = isSprinting
- end
- UserInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.LeftShift then
- toggleSprint(true)
- elseif input.KeyCode == Enum.KeyCode.Space then
- -- Double Jump handling
- local currentTime = tick()
- if humanoid:GetState() == Enum.HumanoidStateType.Freefall and canDoubleJump and (currentTime - lastJumpTime > doubleJumpCooldown) then
- canDoubleJump = false
- lastJumpTime = currentTime
- -- Move the character forward instead of upward
- local forwardDirection = character.HumanoidRootPart.CFrame.lookVector * 50
- character.HumanoidRootPart.Velocity = Vector3.new(forwardDirection.X, 0, forwardDirection.Z)
- -- Reset double jump after cooldown
- task.delay(doubleJumpCooldown, function()
- canDoubleJump = true
- end)
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.LeftShift then
- toggleSprint(false)
- end
- end)
- -- Set initial walk speed
- humanoid.WalkSpeed = walkSpeed
- -- Check for water terrain and place part: Create a platform if the player is sprinting over water
- RunService.RenderStepped:Connect(function()
- if sprinting then
- local ray = Ray.new(character.HumanoidRootPart.Position, Vector3.new(0, -5, 0))
- local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {character})
- 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
- local waterPart = Instance.new("Part")
- waterPart.Size = Vector3.new(5, 1, 5)
- waterPart.Anchored = true
- waterPart.CanCollide = true
- waterPart.Transparency = 0.5
- waterPart.Position = position + Vector3.new(0, -1, 0)
- waterPart.Parent = workspace
- -- Remove the part after a short delay
- Debris:AddItem(waterPart, 0.1)
- end
- end
- end)
- -- Change body part colors: Set the character's arms to tan, legs to blue, and torso to tan
- local function setBodyColors()
- local function changeColor(partName, color)
- local part = character:FindFirstChild(partName)
- if part then
- part.BrickColor = BrickColor.new(color)
- end
- end
- changeColor("LeftArm", "Tan")
- changeColor("RightArm", "Tan")
- changeColor("LeftLeg", "Bright blue")
- changeColor("RightLeg", "Bright blue")
- changeColor("Torso", "Tan")
- end
- -- Set colors on character load: Apply colors when the character is loaded or respawned
- if character then
- setBodyColors()
- end
- player.CharacterAdded:Connect(function(newCharacter)
- character = newCharacter
- humanoid = character:WaitForChild("Humanoid")
- setBodyColors()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement