Hi again. Earlier I asked how do I make this teleport script E to activate instead of mouse button 1. I got some help but as a beginner scripter and a lack of understanding on my part I failed to make the script work...nevertheless here is my attempt. would love some correction.
local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local teleports = workspace:WaitForChild("Teleports")
local enterButton = script.Parent.enterButton
local range = 5
local exitPart
UserInputService.InputBegan:Connect(function(GameProcessed, InputType)
if not (GameProcessed) then return end
if (InputType == Enum.KeyCode.E) then
if exitPart then
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
if hrp then
hrp.CFrame = exitPart.CFrame + Vector3.new(0,3,0)
end
end
end
end)
game:GetService("RunService").RenderStepped:connect(function()
for _,door in pairs(teleports:GetChildren()) do
if door.Name:sub(0,4) == "Door" then
local exit = teleports:FindFirstChild("Exit"..door.Name:sub(5))
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
if hrp then
if (door.Position-hrp.Position).magnitude < range then
if not enterButton.Visible then
enterButton.Visible = true
end
else
if enterButton.Visible then enterButton.Visible = false end
exitPart = exit
end
end
end
end
end
