how would i make a script that when pressed “Space key” you can teleport somewhere and when you press it again you teleport back
Like, teleport you to a random place or?
Use a local script to listen for when someone presses the space bar, I’d suggesting using ContextActionService - ContextActionService
with that setup could then send a remote event to a server side script which is listening to the remote event, and inside that script have it listen for if that player has sent a teleport request once already or not, if not then teleport them wherever, and then update your variables on the server script to indicate they’ve been teleported, where from, and then actually teleport them. This is so that when they press space again your if statement sees this change, sends them back to where they were, and update your variables to clear them out for use again
a specific location example 123,123,123
Do u mean smthing like this (put in startercharacterscripts)
local uis = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space then
char.HumanoidRootPart.CFrame = workspace.Part.CFrame
end
end)
i mean like positions like example: 123,123,123
Ok, try this:
EDIT: Fixed code to check if the character exists.
local hastp = false
local lastpos = nil
game:GetService("UserInputService").InputBegan:Connect(function(input) --Detects if an input started
if not game:GetService("Players").LocalPlayer.Character then return end
local hrp = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart
if input.KeyCode == Enum.KeyCode.Space then
if hastp then
hrp.CFrame = lastpos
else
lastpos = hrp.CFrame
hrp.CFrame = CFrame.new(Vector3.new(poshere)) --replace 'poshere' with your position
end
hastp = not hastp
end
end)