Hello!
I would like to make a script where when I press a certain button, It will disable jumping for all users that are inside the game and not just myself.
Hello!
I would like to make a script where when I press a certain button, It will disable jumping for all users that are inside the game and not just myself.
What have you tried so far? Are you able to print("Key pressed")
when a key was pressed as a first step?
You can use a remote event. Send a request to the server and validate the signal to prevent abuse. From server, loop through a table of all players using game:GetService(“Players”):GetPlayers() and set their jump power to zero. Jump power is a property of humanoid, so players unfortunately have control over it and there isn’t much you can do about that. However, save default jump power value (variable) and set all Humanoid.JumpPower values to 0. But how to reverse the action after a couple of seconds? Call a coroutine. Wrap a function using coroutine.wrap()() and wait for a short time interval. Loop through all players again and reset jump power.
EDIT (2021-03-06)
@galaxy63197 you can base off of the following.
It’s relatively similar to @Astroclusions’s idea and exactly what I close to what I meant with my previous answer.
Local script, belongs inside your button
local disableJumpEvent = game:GetService("ReplicatedStorage").DisableJumpEvent
script.Parent.Activated:Connect(function()
disableJumpEvent:FireServer()
end)
Server script, belongs in ServerScriptService
local Players = game:GetService("Players")
local NO_JUMP_TIME = 5
local disableJumpEvent = game:GetService("ReplicatedStorage").DisableJumpEvent
local jump_enabled = true
local function cooldown()
jump_enabled = false
wait(NO_JUMP_TIME)
jump_enabled = true
loopThroughPlayerList(true)
end
function loopThroughPlayerList(enableJumping)
local char, humanoid
for _, player in pairs(Players:GetPlayers()) do
char = player.Character
humanoid = char and char:WaitForChild("Humanoid")
if (humanoid) then
humanoid.JumpPower = enableJumping and 50 or 0
end
end
end
disableJumpEvent.OnServerEvent:Connect(function(player)
if (jump_enabled) then
loopThroughPlayerList(false) -- temporarily disable jumping
coroutine.wrap(cooldown)() -- separate thread; wait and enable jumping again
end
end)
There should a remote event named DisableJumpEvent in ReplicatedStorage.
Keep in mind that this is a basic concept of how you could achieve this. Currently, every player can stun each other. Only players who are allowed to disable jumping should have the button in their PlayerGui. While that prevents a usual player from preventing jumping, it’s still not exploiter proof, so you should check if player is eligible to disabling server-side.
Sorry for late response, this is what I’ve done so far.
You could simply just do this:
NOButton.MouseButton1Click:Connect(function()
for i, v in ipairs(game.Players:GetChildren())
if workspace:FindFirstChild(v.Name) then
v.Character.Humanoid.JumpPower = 0
end
end
end)
Thank you, I’ll try it on my game and tell you the results.
Alright, here we go.
(This one is not via button, but via keyboard so it will be faster if you would like to.)
First, add two RemoteEvents to ReplicatedStorage and name them TurnOn and TurnOff.
Then, add a LocalScript to the StarterGui.
LocalScript:
local uis = game:GetService(“UserInputService”)
local player = game.Players.LocalPlayer
local PlayerThatCanUse = “Reksioq3_2” – your nameuis.InputBegan:Connect(function(input)
if player.Name == PlayerThatCanUse then
if input.KeyCode == Enum.KeyCode.E then – change E to button that you want
game.ReplicatedStorage.TurnOn:FireServer()
end
end
end)game.ReplicatedStorage.TurnOn.OnClientEvent:Connect(function()
player.Character.Humanoid.JumpPower = 0
end)game.ReplicatedStorage.TurnOff.OnClientEvent:Connect(function()
player.Character.Humanoid.JumpPower = 50
end)
Then, add a script to ServerScriptService.
Script:
local on = false
game.ReplicatedStorage.TurnOn.OnServerEvent:Connect(function()
if on == false then
on = true
game.ReplicatedStorage.TurnOn:FireAllClients()
elseif on == true then
on = false
game.ReplicatedStorage.TurnOff:FireAllClients()
end
end)
@galaxy63197 and others, I don’t mean to be rude, but did you even read my post? I appreciate your help, but I already took my time and explained the basic concept already above, answers are now repeating starting to repeat.
I’m so sorry, I did actually use your code but forgot to reply and say thank you, once again, sorry for the delay.