Lets make this work with filtering enabled,
We will use your script you made to decide the lanes value, then we will send those over to the server through a remoteevent, multiplying it by the variable Mul(default is 200) then set the body force's X to that, it will create a body force when the local script loads, resetting will not cause a problem for it will redo it.
place a RemoteEvent inside workspace called "Lane"
LocalScript inside StarterPack
workspace:WaitForChild(game.Players.LocalPlayer.Name)
workspace:WaitForChild("Lane"):FireServer(0,true)
local lanes = 0
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.D then
print("D was pressed")
lanes = lanes + 1
print(lanes)
print("--------------")
workspace.Lane:FireServer(lanes)
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.A then
print("A was pressed")
lanes = lanes - 1
print(lanes)
print("--------------")
workspace.Lane:FireServer(lanes)
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
while lanes == 3 do
lanes = lanes - 1
end
while lanes == -3 do
lanes = lanes + 1
end
Regular script inside workspace
local rem=workspace:WaitForChild("Lane")
local mul = 200
rem.OnServerEvent:connect(function(player,lane,it)
if it~=nil and it==true then
if workspace:FindFirstChild(player.Name)~=nil then
if workspace:FindFirstChild(player.Name):FindFirstChild("UpperTorso")~=nil then
Instance.new("BodyForce",workspace:FindFirstChild(player.Name).UpperTorso).Force=Vector3.new(0,0,0)
elseif workspace:FindFirstChild(player.Name):FindFirstChild("Torso")~=nil then
Instance.new("BodyForce",workspace:FindFirstChild(player.Name).Torso).Force=Vector3.new(0,0,0)
end
end
elseif it==nil then
if workspace:FindFirstChild(player.Name)~=nil then
if workspace:FindFirstChild(player.Name):FindFirstChild("UpperTorso")~=nil then
if workspace:FindFirstChild(player.Name).UpperTorso:FindFirstChild("BodyForce")~=nil then
local t = workspace:FindFirstChild(player.Name).UpperTorso
workspace:FindFirstChild(player.Name).UpperTorso.BodyForce.Force=Vector3.new(((t.CFrame.rightVector.X)*lane)*mul,0,((t.CFrame.rightVector.Z)*lane)*mul)
end
elseif workspace:FindFirstChild(player.Name):FindFirstChild("Torso")~=nil then
if workspace:FindFirstChild(player.Name).Torso:FindFirstChild("BodyForce")~=nil then
local t = workspace:FindFirstChild(player.Name).Torso
workspace:FindFirstChild(player.Name).Torso.BodyForce.Force=Vector3.new(((t.CFrame.rightVector.X)*lane)*mul,0,((t.CFrame.rightVector.Z)*lane)*mul)
end
end
end
end
end)
Hoped this helped if you have any questions please do ask :)
1 comment
I think you just write: Varible = Instance.new("BodyForce",Player) then change the values by adressing Varible.Force