Answered by
7 years ago Edited 7 years ago
Hi there,
So, you would like a script that disables jumping in a part, however, based on your script above, when you set jump to false, the player is still able to jump as that option only can detect if a player is jumping, whereby when the player pressed spacebar, Jump will turn to true before turning back to false. Thus, in order to stop a player from jumping, you should use JumpPower. By default, the player can jump to a JumpPower of 50, So, setting the JumpPower to 0 will force the player to be unable to jump. Additionally, in order to make just a single player do it, you should write your script inside a local script and parent it under StarterPack. Since the StarterPack only loads when the player loads in, the script will only activate when the player joins the game.
If your game is to be not filtering enabled (In experimental mode), server scripts and local scripts will not be able to communicate with each other so I do suggest that you put a remote event such that when on Touch, activate the remote event to the local script.
So here is what your script should look like:
I do suggest using filtering enabled to prevent hackers.
1 If you don't have filtering enabled.
Local script:
01 | local detecttouch = game.Workspace.(Part detector's name) |
04 | detecttouch.Touched:connect( function (hit) |
06 | humanoid = hit.Parent.FindFirstChild( "Humanoid" ) |
09 | humanoid.JumpPower = 0 |
14 | detecttouch.TouchEnded:connect( function (hit) |
16 | humanoid = hit.Parent.FindFirstChild( "Humanoid" ) |
18 | humanoid.JumpPower = 50 |
2 If you have filtering enabled
Server script:
02 | local RemoteEvent = instance.new("RemoteEvent) |
03 | RemoteEvent.Parent = game.WaitForChild( "ReplicatedStorage" ) |
04 | RemoteEvent.Name = "ActivateTouch" |
07 | local RemoteEvent = instance.new("RemoteEvent) |
08 | Touchends.Parent = game.WaitForChild( "ReplicatedStorage" ) |
09 | Touchends.Name = "Touchend" |
11 | local detecttouch = game.Workspace.(Part detector's name) |
14 | detecttouch.Touched:connect( function (hit) |
16 | humanoid = hit.Parent.FindFirstChild( "Humanoid" ) |
19 | local player = hit.Parent.GetPlayerFromCharacter() |
20 | RemoteEvent:FireClient(player) |
25 | detecttouch.TouchEnded:connect( function (hit) |
27 | humanoid = hit.Parent.FindFirstChild( "Humanoid" ) |
28 | local player = hit.Parent.GetPlayerFromCharacter() |
29 | Touchends:FireClient(player) |
In localscript:
01 | local remoteEvent = game.ReplicatedStorage:WaitForChild( "ActivateTouch" ) |
02 | local Touchends = game.ReplicatedStorage:WaitForChild( "Touchend" ) |
05 | remoteEvent.OnClientEvent:connect( function (player) |
06 | player.Character.Humanoid.JumpPower = 0 |
10 | Touchends.OnClientEvent:connect( function (player) |
11 | player.Character.Humanoid.JumpPower = 50 |