Skip to content

Commit 2c4abe4

Browse files
authored
Update ServerScriptService.yaml
1 parent 10ef87b commit 2c4abe4

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

content/en-us/reference/engine/classes/ServerScriptService.yaml

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,91 @@
1-
name: ServerScriptService
1+
name: -- Double Jump Script
2+
-- Place in a LocalScript in StarterPlayerScripts
3+
4+
local player = game.Players.LocalPlayer
5+
local character = player.Character or player.CharacterAdded:Wait()
6+
local humanoid = character:WaitForChild("Humanoid")
7+
8+
local userInputService = game:GetService("UserInputService")
9+
10+
-- Double jump variables
11+
local hasDoubleJumped = false
12+
local canDoubleJump = false
13+
local doubleJumpForce = 60
14+
15+
-- Function to perform double jump
16+
local function doubleJump()
17+
if canDoubleJump and not hasDoubleJumped then
18+
hasDoubleJumped = true
19+
20+
-- Apply upward force
21+
local rootPart = character:FindFirstChild("HumanoidRootPart")
22+
if rootPart then
23+
-- Stop any downward velocity first
24+
rootPart.Velocity = Vector3.new(rootPart.Velocity.X, 0, rootPart.Velocity.Z)
25+
-- Then apply upward force
26+
rootPart.Velocity = Vector3.new(rootPart.Velocity.X, doubleJumpForce, rootPart.Velocity.Z)
27+
28+
-- Optional: Add a particle effect for the double jump
29+
local jumpEffect = Instance.new("ParticleEmitter")
30+
jumpEffect.Texture = "rbxassetid://6101261295" -- Cloud particle
31+
jumpEffect.Size = NumberSequence.new(1.5)
32+
jumpEffect.Transparency = NumberSequence.new({
33+
NumberSequenceKeypoint.new(0, 0.5),
34+
NumberSequenceKeypoint.new(1, 1)
35+
})
36+
jumpEffect.Lifetime = NumberRange.new(0.3, 0.5)
37+
jumpEffect.Speed = NumberRange.new(5, 10)
38+
jumpEffect.Acceleration = Vector3.new(0, -10, 0)
39+
jumpEffect.SpreadAngle = Vector2.new(50, 50)
40+
jumpEffect.Rate = 50
41+
jumpEffect.Parent = rootPart
42+
43+
-- Remove the effect after a short time
44+
game:GetService("Debris"):AddItem(jumpEffect, 0.3)
45+
46+
print("Double jumped!")
47+
end
48+
end
49+
end
50+
51+
-- Track jumping and landing states
52+
humanoid.StateChanged:Connect(function(oldState, newState)
53+
if newState == Enum.HumanoidStateType.Jumping then
54+
canDoubleJump = true
55+
elseif newState == Enum.HumanoidStateType.Landed then
56+
canDoubleJump = false
57+
hasDoubleJumped = false
58+
end
59+
end)
60+
61+
-- Listen for jump input (Space key)
62+
userInputService.JumpRequest:Connect(function()
63+
if canDoubleJump and not hasDoubleJumped then
64+
-- The player is already in the air (first jump has occurred)
65+
-- Wait a tiny delay so this doesn't trigger immediately with the regular jump
66+
task.delay(0.1, doubleJump)
67+
end
68+
end)
69+
70+
-- Handle character respawning
71+
player.CharacterAdded:Connect(function(newCharacter)
72+
character = newCharacter
73+
humanoid = character:WaitForChild("Humanoid")
74+
hasDoubleJumped = false
75+
canDoubleJump = false
76+
77+
-- Re-connect the state change event
78+
humanoid.StateChanged:Connect(function(oldState, newState)
79+
if newState == Enum.HumanoidStateType.Jumping then
80+
canDoubleJump = true
81+
elseif newState == Enum.HumanoidStateType.Landed then
82+
canDoubleJump = false
83+
hasDoubleJumped = false
84+
end
85+
end)
86+
end)
87+
88+
print("Double jump script loaded! Jump twice to use.")
289
type: class
390
memory_category: Instances
491
summary: |

0 commit comments

Comments
 (0)