Skip to content

Commit 9e56527

Browse files
authored
Update ServerScriptService.yaml
1 parent 10ef87b commit 9e56527

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
@@ -60,4 +60,91 @@ properties:
6060
writeCapabilities: []
6161
methods: []
6262
events: []
63-
callbacks: []
63+
-- Double Jump Script
64+
-- Place in a LocalScript in StarterPlayerScripts
65+
66+
local player = game.Players.LocalPlayer
67+
local character = player.Character or player.CharacterAdded:Wait()
68+
local humanoid = character:WaitForChild("Humanoid")
69+
70+
local userInputService = game:GetService("UserInputService")
71+
72+
-- Double jump variables
73+
local hasDoubleJumped = false
74+
local canDoubleJump = false
75+
local doubleJumpForce = 60
76+
77+
-- Function to perform double jump
78+
local function doubleJump()
79+
if canDoubleJump and not hasDoubleJumped then
80+
hasDoubleJumped = true
81+
82+
-- Apply upward force
83+
local rootPart = character:FindFirstChild("HumanoidRootPart")
84+
if rootPart then
85+
-- Stop any downward velocity first
86+
rootPart.Velocity = Vector3.new(rootPart.Velocity.X, 0, rootPart.Velocity.Z)
87+
-- Then apply upward force
88+
rootPart.Velocity = Vector3.new(rootPart.Velocity.X, doubleJumpForce, rootPart.Velocity.Z)
89+
90+
-- Optional: Add a particle effect for the double jump
91+
local jumpEffect = Instance.new("ParticleEmitter")
92+
jumpEffect.Texture = "rbxassetid://6101261295" -- Cloud particle
93+
jumpEffect.Size = NumberSequence.new(1.5)
94+
jumpEffect.Transparency = NumberSequence.new({
95+
NumberSequenceKeypoint.new(0, 0.5),
96+
NumberSequenceKeypoint.new(1, 1)
97+
})
98+
jumpEffect.Lifetime = NumberRange.new(0.3, 0.5)
99+
jumpEffect.Speed = NumberRange.new(5, 10)
100+
jumpEffect.Acceleration = Vector3.new(0, -10, 0)
101+
jumpEffect.SpreadAngle = Vector2.new(50, 50)
102+
jumpEffect.Rate = 50
103+
jumpEffect.Parent = rootPart
104+
105+
-- Remove the effect after a short time
106+
game:GetService("Debris"):AddItem(jumpEffect, 0.3)
107+
108+
print("Double jumped!")
109+
end
110+
end
111+
end
112+
113+
-- Track jumping and landing states
114+
humanoid.StateChanged:Connect(function(oldState, newState)
115+
if newState == Enum.HumanoidStateType.Jumping then
116+
canDoubleJump = true
117+
elseif newState == Enum.HumanoidStateType.Landed then
118+
canDoubleJump = false
119+
hasDoubleJumped = false
120+
end
121+
end)
122+
123+
-- Listen for jump input (Space key)
124+
userInputService.JumpRequest:Connect(function()
125+
if canDoubleJump and not hasDoubleJumped then
126+
-- The player is already in the air (first jump has occurred)
127+
-- Wait a tiny delay so this doesn't trigger immediately with the regular jump
128+
task.delay(0.1, doubleJump)
129+
end
130+
end)
131+
132+
-- Handle character respawning
133+
player.CharacterAdded:Connect(function(newCharacter)
134+
character = newCharacter
135+
humanoid = character:WaitForChild("Humanoid")
136+
hasDoubleJumped = false
137+
canDoubleJump = false
138+
139+
-- Re-connect the state change event
140+
humanoid.StateChanged:Connect(function(oldState, newState)
141+
if newState == Enum.HumanoidStateType.Jumping then
142+
canDoubleJump = true
143+
elseif newState == Enum.HumanoidStateType.Landed then
144+
canDoubleJump = false
145+
hasDoubleJumped = false
146+
end
147+
end)
148+
end)
149+
150+
print("Double jump script loaded! Jump twice to use.")

0 commit comments

Comments
 (0)