Hello, I'm making a 2D game on Roblox. I have it so when you press W on the keyboard the collisions for the trusses are turned on, however, this only works on PCs or other keyboard enabled devices, can any one help me with this. Here is my code, I'm new to scripting so it'll probably look a bit messy.

local L = game.workspace.T1
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.W and L.CanCollide == false then 
			L.CanCollide = true
		end
	end)
userInputService.InputBegan:connect(function(inputObject)
	 if inputObject.KeyCode == Enum.KeyCode.Space and L.CanCollide == true then
			L.CanCollide = false
		
	end
end)
userInputService.InputBegan:connect(function(inputObject)
	 if inputObject.KeyCode == Enum.KeyCode.Space and inputObject.KeyCode == Enum.KeyCode.W  then
			L.CanCollide = true
		
	end
end)

2 comments

0

why do you make people press W to turn on collision? you could just leave it on the whole time lol

0

Because, when people move back and forth infront of the ladder they climb up it, I want it so you can only climb the ladder if you're actually facing towards it, like in an actual 2D game