I’d like to try adding mobile to my game and I thought of using JumpRequest to detect when the player presses the jump button, however, it doesn’t work at all, not even on PC.
local UserInput = game:GetService("UserInputService");
UserInput.JumpRequest:Connect(function()
print("Jump!");
end);
This doesn’t print anything when I press the spacebar or the jump button. I don’t know if I’m missing something. Any help is appreciated.
In my character, I insert it manually from the main server script. I tried on an empty baseplate and the code works fine in there. There’s probably something in my game that doesn’t make it fire for some reason.
When LocalScripts are inserted to a client from the server, those scripts tend to not work. It’s a strange thing that happens but I’ve noticed that happen when I tried to do it. I don’t remember how I fixed it, I think I used a RemoteEvent to signal to the client that they would be receiving the script and then I would Disable it and Enable it in the client or something like that.
I think Chris is right, I don’t know what other input (if any) you wanted to capture but a remote event might look like…
local UserInputService = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local EventJump = RS:FindFirstChild("Event Jump") --manually add or script in
local Player = game.Players.LocalPlayer
local character = Player.Character
local DB = false
local function onInputBegan(input, gameProcessed)
UserInputService.JumpRequest:Connect(function()
--add input checks if wanted
if DB == false then
DB = true
EventJump:FireServer(Player)
end
end)
wait()
DB = false
end
UserInputService.JumpRequest:Connect(onInputBegan)
and of course the ServerScript…
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local EventJump = RS:FindFirstChild("Event Jump")
local function onEventJumpFired(player)
print(player.Name, "Tried to jump!")
end
EventJump.OnServerEvent:Connect(onEventJumpFired)
i’m telling u i’ve gone through this same thing before. the only way to fix it is to implement RemoteEvents and not parent LocalScripts through the server. This gives the Server ownership over the LocalScript when the client should have ownership over it.
Instead try something like this. Put a RemoteEvent in ReplicatedStorage, a Script in ServerScriptService, and a LocalScript in StarterCharacterScripts. Now, use the following code to enable/disable the event.
In the LocalScript in StarterCharacterScripts:
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- name it and place it wherever, as long as it's replicated
local UserInputService = game:GetService("UserInputService")
local JumpRequestEventEnabled = false
UserInputService.JumpRequest:Connect(function()
if JumpRequestEventEnabled then
-- code here because it's enabled
end
end)
RemoteEvent.OnClientEvent:Connect(function(Enabled)
JumpRequestEventEnabled = Enabled
--[[
via the RemoteEvent, you can toggle whether the event is enabled or not,
which is essentially what you're doing by parenting a local script from the server
]]
end)
In the Script in ServerScriptService:
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
repeat wait() until Character:FindFirstChild("LocalScript") -- or whatever you named the LocalScript
RemoteEvent:FireClient(Player, true)
-- sets the jump request event to enabled when the character is added
end)
end)
Incorrect, if you parent the script to the character it will automatically transfer its ownership to the client as the character is controlled by the client (in fact, if you try to destroy the script por any other instance from your character from the client, it will replicate). Otherwise, by using your logic, normal UserInputService events (such as InputBegan and InputEnded) shouldn’t work too, but they do. Anyways, i’ve tried putting the code on a LocalScript parented to StarterCharacterScripts and yet it still doesn’t work. I’m wondering if there’s some settings that I touched and those are affecting it? Because I checked and the “Jump” property of the humanoid changes when the player jumps, so still not sure why it wouldn’t work only in a specific game.
I know they aren’t necessary. I’m just used to putting them, I don’t even notice them anymore. Also putting it in StarterGui doesn’t change anything. Thanks for the answer tho.
if you made your own control script, remember that this event only fires when the client receives input from the player to jump, not when the humanoid’s jump value is set to true.