Hey everyone, was just creating a 2d line runner game and needed help with the player being able to press "left/right" to switch lanes.
This is the turn script.
right = game:GetService("UserInputService")
left = game:GetService("UserInputService")
plr = game.Players.LocalPlayer
Hplr = plr:GetPlayerFromCharacter(plr)
x = Vector3.new(math.random(1,10),0,0)
z = Vector3.new(0,0,math.random(1,10))
local function GoLeft()
if Hplr.HumanoidRootPart then
plr.Position += x
end
end
local function GoRight()
plr:Move(Vector3.new(0,0,z))
end
left.InputBegan:Connect(function(left)
if left.KeyCode == Enum.KeyCode.Left
then
GoLeft()
end
end)
right.InputBegan:Connect(function(right)
if right.KeyCode == Enum.KeyCode.Left
then
GoRight()
end
end)
would be happy to know what I've done wrong. I'm pretty new to scripting.
Thanks again c=
Edit: Script is in starterPlayerScripts btw

3 comments
you can just use CFrame
also which script are you using, it should be an script not a local script, also try putting this script in serverscriptservice
Ok so I've gotten a script from @Packayee but now Im recieving the error of "x/z can't be assigned to" any clues?