Hello hello!
I’m working on a marble run game where the players are converted into marbles and go down a marble run. The players are able to control whenever the marble is able to jump or use an ability by using the Context Action Service.
Originally I had a RemoteEvent send a request to the server and make the ball jump from there, although there seems to be a slight delay from when I press space to when the ball jumps.
I tried changing this through the client via a localscript inside StarterPlayerScripts but now the velocity does not change at all. And I’ve also set the network ownership of the ball to the player, and it has made no difference.
Here is the localscript below. Any help is appreciated, thank you!
--\\ CUSTOMIZABLES //--
local JUMP_KEY = Enum.KeyCode.Space
local ABILITY_KEY = Enum.KeyCode.E
local JUMP_CONT = Enum.KeyCode.ButtonA
local ABILITY_CONT = Enum.KeyCode.ButtonX
--\\ VARIABLES //--
local ContextActionService = game:GetService('ContextActionService')
local UserInputService = game:GetService('UserInputService')
local inputRemote = game:GetService('ReplicatedStorage').Events.InputRequest
local player = game:GetService('Players').LocalPlayer
--\\ FUNCTIONS //--
local function inputRequest(actionName, inputState, inputObj)
--// Check if player is marble
if game.Workspace.Marbles:FindFirstChild(player.Name) then
if inputState == Enum.UserInputState.Begin then
--// Check for jump
if actionName == 'Jump' then
local marble = game.Workspace.Marbles:FindFirstChild(player.Name)
if marble then
marble.Ball.Velocity = Vector3.new(marble.Ball.Velocity.X, 100, marble.Ball.Velocity.Z)
end
--// Check for ability
elseif actionName == 'Ability' then
--TODO_ABILITY_STUFF
end
end
end
end
--\\ EVENT //--
ContextActionService:BindAction('Jump', inputRequest, true, JUMP_KEY, JUMP_CONT)
ContextActionService:BindAction('Ability', inputRequest, true, ABILITY_KEY, ABILITY_CONT)