So again… I’m making a side scroller and in my game I have ‘layers’ that the player is in and they’re able to switch between them with ‘W’ and ‘S’. It sort of works other than the fact that sometimes you move right off the map or into the scenery where it’s not suppose to allow you to go…
local MaxLayers = 3
local PlrLayer = 1
elseif Input.KeyCode == Enum.KeyCode.W then -- Move Forwards
if PlrLayer ~= MaxLayers then
PlrLayer = PlrLayer + 1
print("Moved Forwards, ".. PlrLayer)
local root = player.Character:FindFirstChild("HumanoidRootPart")
root.CFrame = root.CFrame * CFrame.new(-4,0,0)
end
elseif Input.KeyCode == Enum.KeyCode.S then -- Move Backwards
if PlrLayer ~= 1 then
PlrLayer = PlrLayer - 1
print("Moved Backwards, ".. PlrLayer)
local root = player.Character:FindFirstChild("HumanoidRootPart")
root.CFrame = root.CFrame * CFrame.new(4,0,0)
end
end
It will typically work “okay” for a moment but then you’ll get times where it will print “Moved Forward a Layer” and it’ll literally move you backwards a layer and off the map to your death…