|
1 | | -name: ServerScriptService |
2 | | -type: class |
3 | | -memory_category: Instances |
4 | | -summary: | |
5 | | - A container service for server-only `Class.Script` objects. |
6 | | -description: | |
7 | | - **ServerScriptService** is a container service for `Class.Script`, |
8 | | - `Class.ModuleScript` and other scripting-related assets that are only meant |
9 | | - for server use. The contents are never replicated to player clients at all, |
10 | | - which allows for a secure storage of important game logic. Script objects will |
11 | | - run if they are within this service and not |
12 | | - `Class.BaseScript.Disabled|Disabled`. |
13 | | -
|
14 | | - This service houses just one property, |
15 | | - `Class.ServerScriptService.LoadStringEnabled|LoadStringEnabled`, which |
16 | | - determines whether the `loadstring` function in Luau is enabled. It's |
17 | | - recommended to keep this disabled for security reasons, as misusing this |
18 | | - function can lead to remote code execution vulnerabilities. |
19 | | -
|
20 | | - Scripts running in ServerScriptService may need access to various other assets |
21 | | - which are not scripting-related, such as prefabricated models to be |
22 | | - `Class.Instance:Clone()|cloned`. Such assets should go in |
23 | | - `Class.ServerStorage`, which behaves similarly to this service except that |
24 | | - `Class.Script` objects will not run even if they are not |
25 | | - `Class.BaseScript.Disabled|Disabled`. Assets and `Class.ModuleScript` that are |
26 | | - useful to both the server and clients should go in `Class.ReplicatedStorage` |
27 | | - instead. Finally, you can further organize objects within this service through |
28 | | - the use of `Class.Folder|Folders` without affecting the way it behaves. |
29 | | -code_samples: [] |
30 | | -inherits: |
31 | | - - Instance |
32 | | -tags: |
33 | | - - NotCreatable |
34 | | - - Service |
35 | | - - NotReplicated |
36 | | -deprecation_message: '' |
37 | | -properties: |
38 | | - - name: ServerScriptService.LoadStringEnabled |
39 | | - summary: | |
40 | | - Toggles whether or not the `loadstring` function can be used by server |
41 | | - scripts. Defaults to false. |
42 | | - description: | |
43 | | - Toggles whether or not the `loadstring` function can be used by server |
44 | | - scripts. Defaults to false. |
45 | | - code_samples: [] |
46 | | - type: boolean |
47 | | - tags: |
48 | | - - NotReplicated |
49 | | - - NotScriptable |
50 | | - deprecation_message: '' |
51 | | - security: |
52 | | - read: None |
53 | | - write: None |
54 | | - thread_safety: ReadSafe |
55 | | - category: Behavior |
56 | | - serialization: |
57 | | - can_load: true |
58 | | - can_save: true |
59 | | - capabilities: [] |
60 | | - writeCapabilities: [] |
61 | | -methods: [] |
62 | | -events: [] |
63 | | -callbacks: [] |
| 1 | +-- 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.")-methods:[]-events[]-callbacks:[] |
0 commit comments