Velocity problem

So i am making a custom character controller (which is a boll) using velocity I want is velocity in Z axis is always adding up and if you press d it goes right (left is remaining)

this are the scripts:
client script:

--Made By Beastcraft_Gaming--

--28/10/20--

--Variables

--Services

local workSpace = game:GetService("Workspace") -- workSpace

local ReplicatedStorage = game:GetService("ReplicatedStorage") --ReplicatedStorage

local RunService = game:GetService("RunService") --RunService

local ContextActionService = game:GetService("ContextActionService"); --ContextActionService

--Instances

local player = workSpace:WaitForChild("player"); --player

local camera = workSpace.CurrentCamera; --camera

local PushRemote = ReplicatedStorage:WaitForChild("PlayerRemotes"):WaitForChild("Push"); --PushRemote

local LeftRemote = ReplicatedStorage:WaitForChild("PlayerRemotes"):WaitForChild("Left");  --LeftRemote

--Values

local offSet = Vector3.new(0,4,10);

--Miscelenious

local LeftAction = "Left"

--Properties

camera.CameraType = Enum.CameraType.Scriptable; --so script can change it

--functions

local function OnRenderStep()

  local newOffSet = offSet + player.Position;

  camera.CFrame = CFrame.new(newOffSet);

  PushRemote:FireServer(RunService.Heartbeat:Wait())

end

local function OnLeftUserInput(ActionName, InputeState, InputObject)

  print('EventFired'); --it prints

  if ActionName == "Left" and InputeState == Enum.UserInputState.Begin then

      LeftRemote:FireServer(RunService.Heartbeat:Wait())

  end

end

--Events

RunService.RenderStepped:Connect(OnRenderStep)

ContextActionService:BindAction(LeftAction, OnLeftUserInput, false, Enum.KeyCode.D);

print(camera.CFrame.Position); --prints the position

print(player.CFrame.Position); --prints the position

Server script:

--Made By Beastcraft_Gaming--

--28/10/20--

--Variables

--Services

local workSpace = game:GetService("Workspace"); --WorkSpace

local ReplicatedStorage = game:GetService("ReplicatedStorage"); --ReplicatedStorage

local RunService = game:GetService("RunService"); --RunService

--Instances

local player = workSpace:WaitForChild("player"); --player

local PushRemote = ReplicatedStorage:WaitForChild("PlayerRemotes"):WaitForChild("Push"); --PushRemote

local LeftPushRemote = ReplicatedStorage:WaitForChild("PlayerRemotes"):WaitForChild("Left"); --LeftRemote

--functions

local function push(deltaTime)

    player.Velocity = Vector3.new(0,0,-50)

    wait(deltaTime)

end

local function LeftPush(deltaTime)

    print("This fired"); --it prints

    player.Velocity = player.Velocity + Vector3.new(100,0,0); --it is set so high so I can see the change

    wait(deltaTime)

end

--events

PushRemote.OnServerEvent:Connect(function(deltaTime)

    push(deltaTime)

end)

LeftPushRemote.OnServerEvent:Connect(function(deltaTime)

    LeftPush(deltaTime);

end)

so the problem is the velocity on Z works fine but velocity on X axis doesnt work…

3 Likes

I’m not enough advanced but I just got a question: why do you use game:getservice(“Workspace”) ? Roblox automatically has a variable “workspace”

1 Like

For a clearer code, also workspace can be used in more things.

Idk I just make the code looks cleaner for me lol.

Welp no-ones replying now R.I.P me.

On your server script and on your first local function you never put a print to test it out maybe that will help you.

Thanks for answering but I figured it out

the problem was that the forward push was given every frame rendered but the left push was only given once so I fixed it I made a boolean variable LeftInput so when player presses the button it turns true and false on inputend and in renderstep I checked if the boolean was true it gives the force repeatedly.