I’m making a script that requires the player to press W while touching a part, to teleport to someplace else, but I can’t do this, because for .Touched to work, the player needs to be moving, and moving and pressing W makes it hard to teleport to a position. Here’s my code:
local UIS = game:GetService("UserInputService")
local Level1Folder = game.Workspace:FindFirstChild("Level1")
local Level2Folder = game.Workspace:FindFirstChild("Level2")
local Level3Folder = game.Workspace:FindFirstChild("Level3")
local Level4Folder = game.Workspace:FindFirstChild("Level4")
local TPKey = Enum.KeyCode.W
Level1Folder.ExitPoint.Touched:Connect(function(partTouching)
if partTouching.Parent:FindFirstChild("Humanoid") then
if UIS:IsKeyDown(TPKey) == true then
partTouching.Parent:SetPrimaryPartCFrame(CFrame.new(
Level2Folder.EntryPoint.Position + Vector3.new(0, 10, 0)
)
)
end
end
end)
Level2Folder.ExitPoint.Touched:Connect(function(partTouching)
if partTouching.Parent:FindFirstChild("Humanoid") then
if UIS:IsKeyDown(TPKey) == true then
partTouching.Parent:SetPrimaryPartCFrame(CFrame.new(
Level3Folder.EntryPoint.Position + Vector3.new(0, 10, 0)
)
)
end
end
end)
Level3Folder.ExitPoint.Touched:Connect(function(partTouching)
if partTouching.Parent:FindFirstChild("Humanoid") then
if UIS:IsKeyDown(TPKey) == true then
partTouching.Parent:SetPrimaryPartCFrame(CFrame.new(
Level4Folder.EntryPoint.Position + Vector3.new(0, 10, 0)
)
)
end
end
end)