local plr = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.Return then
local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidrootpart then
humanoidrootpart.CFrame = CFrame.new(part.CFrame.p) + Vector3.new(0,5,0)
end
end
end
userInputService.InputBegan:Connect(onKeyPress)
local part = game.Workspace:WaitForChild(“TeleportPart1”) – Name of part you want to teleport to
local plr = game.Players.LocalPlayer
local userInputService = game:GetService(“UserInputService”)
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.Return then
local humanoidrootpart = plr.Character:FindFirstChild(“HumanoidRootPart”)
if humanoidrootpart then
humanoidrootpart.CFrame = CFrame.new(part.CFrame.p) + Vector3.new(0,5,0)
end
end
end
userInputService.InputBegan:Connect(onKeyPress)
i believe roblox kept changing my script somehow here is the correct one i think
If you want to make it run one time when the game loads:
Take the code outside of the function and ditch the event
local plr = game.Players.LocalPlayer
plr.CharacterAdded:Wait()
local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidrootpart then
humanoidrootpart.CFrame = CFrame.new(part.CFrame.p) + Vector3.new(0,5,0)
end
If you want to make it run only once when the key is pressed:
make a variable that toggles to true once the function is ran, and don’t run it again if it’s true
local plr = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local completed = false
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.Return then
local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidrootpart and completed == false then
humanoidrootpart.CFrame = CFrame.new(part.CFrame.p) + Vector3.new(0,5,0)
completed = true
end
end
end
userInputService.InputBegan:Connect(onKeyPress)
This will work most of the time. Unfortunately with their current script, I see no way in which they can do this. They want it to fire when the enter key is pressed and not before then. I could easily be missing something as there are a lot of functions related to input, but at present everything I know off the top of my head either isn’t a RBXScriptSignal (so you can’t do :Once()) or it needs to filter out the things that could fire the function before they wanted it to.
Yes, that is true, the :Once() would disconnect even tho the key isn’t the enter key.
In that way, you should disconnect the connection when it’s done:
local plr = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local connection
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.Return then
local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidrootpart then
humanoidrootpart.CFrame = CFrame.new(part.CFrame.p) + Vector3.new(0,5,0)
connection:Disconnect()
end
end
end
connection = userInputService.InputBegan:Connect(onKeyPress)