Good day(or night depends on where you are), I am having trouble degarding teleporting in and out of a vehicle, the teleporting in part works fine but I can’t seem to teleport out of it, here is my code:
local Player = game.Players.LocalPlayer
local Input = game:GetService("UserInputService")
local Plane = workspace["Reaper-A12"]
local Setting = require(Plane.Settings.Config)
local Gear = false
local Canopy = false
local Seat = workspace["Reaper-A12"].MainPart.PilotSeat
local ProxiPromtService = game:GetService("ProximityPromptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportModult = require(ReplicatedStorage:WaitForChild("TeleportToSeat"))
local TeleportEvent = ReplicatedStorage.PlaneEvents:WaitForChild("Teleport")
local Events = ReplicatedStorage:WaitForChild("PlaneEvents")
local Params = {
destination = Seat.Position,
faceAngle = 0,
freeze = true}
Input.InputBegan:Connect(function(Inp, CanWork)
if Inp.KeyCode == Setting.LandingGear and CanWork == true then
print("Gear key pressed.")
if Gear == false then
Events.GearEvent:FireServer("In")
Gear = true
elseif Gear == true then
Events.GearEvent:FireServer("Out")
Gear = false
end
elseif Inp.KeyCode == Setting.Exit and CanWork == true and not ProxiPromtService.PromptTriggered then
print("Exit key pressed.")
Params["destination"] = Params["destination"].Z - 10
TeleportEvent:FireServer(Params)
Seat.ProximityPrompt.Enabled = true
end
end)
local function TeleportToSeat()
Seat.ProximityPrompt.Enabled = false
TeleportEvent:fireServer(Params)
end
ProxiPromtService.PromptTriggered:Connect(TeleportToSeat)
The output did not print both of the print command and there is no error displayed, however it did detect the keys being pressed.Here is my server script, the teleport module script and key code module script if needed.
Server script:
local MainPart = workspace["Reaper-A12"].MainPart
local Engine = MainPart.CenterOfGravity
local Misc = MainPart.Parent.Misc
local Debris = game:GetService("Debris")
local Seat = workspace["Reaper-A12"].MainPart.PilotSeat
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportModult = require(ReplicatedStorage:WaitForChild("TeleportToSeat"))
local Events = ReplicatedStorage:WaitForChild("PlaneEvents")
Events.GearEvent.OnServerEvent:connect(function(client, val)
if val == "In" then
for _,g in pairs(Misc.LandingGear.Open:GetDescendants()) do
if g:IsA("BasePart") then
g.Transparency = 1
g.CanCollide = false
end
end
for _,g in pairs(Misc.LandingGear.Closed:GetDescendants()) do
if g:IsA("BasePart") then
g.Transparency = 0
g.CanCollide = true
end
end
elseif val == "Out" then
for _,g in pairs(Misc.LandingGear.Open:GetDescendants()) do
if g:IsA("BasePart") then
g.Transparency = 0
g.CanCollide = true
end
end
for _,g in pairs(Misc.LandingGear.Closed:GetDescendants()) do
if g:IsA("BasePart") then
g.Transparency = 1
g.CanCollide = false
end
end
end
end)
Events.CanopyEvent.OnServerEvent:Connect(function(Player, Params)
local Character = Player.Character
if not Character or not Character.Parent then
Character = Player.CharacterAdded:TaskWait()
end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid and not Humanoid:GetAttribute("Teleporting") then
Humanoid:SetAttribute("Teleporting", true)
TeleportModult.Teleport(Humanoid, Params)
wait(1)
Humanoid:SetAttribute("Teleporting", nil)
end
end)
Events.Teleport.OnServerEvent:Connect(function(Player, Params)
local Character = Player.Character
if not Character or not Character.Parent then
Character = Player.CharacterAdded:TaskWait()
end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid and not Humanoid:GetAttribute("Teleporting") then
Humanoid:SetAttribute("Teleporting", true)
TeleportModult.Teleport(Humanoid, Params)
wait(1)
Humanoid:SetAttribute("Teleporting", nil)
end
end)
Teleport module script:
local ReplicatedStorage = game.ReplicatedStorage
local Player = game:GetService("Players")
local TeleportToSeat = {}
function TeleportToSeat.Teleport (humanoid, params)
local character = humanoid.Parent
if params.freeze then
humanoid:SetAttribute ("DefaultWalkSpeed", humanoid.WalkSpeed)
humanoid:SetAttribute ("DefaultJumpSpeed", humanoid.JumpPower)
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
end
local rootpartY
if humanoid.RigType == Enum.HumanoidRigType.R15 then
rootpartY = (humanoid.RootPart.Size.Y * 0.5) + humanoid.HipHeight
else
rootpartY = (humanoid.RootPart.Size.Y * 0.5) + humanoid.Parent.LeftLeg.Size.Y + humanoid.HipHeight
end
local Position = CFrame.new(params.destination + Vector3.new(0, rootpartY, 0))
local Orientation = CFrame.Angles(0, math.rad(params.faceAngle), 0)
if workspace.StreamingEnabled then
local Player = Player:GetPlayerFromCharacter(character)
Player:RequestStreamAroundAsync(params.destination)
end
character:SetPrimaryPartCFrame (Position * Orientation)
if params.freeze then
humanoid.WalkSpeed = humanoid:GetAttribute("DefaultWalkSpeed")
humanoid.JumpPower = humanoid:GetAttribute("DefaultJumpSpeed")
end
end
return TeleportToSeat
Key code module script:
local Config = {
MaxSpeed = 1000;
StallSpeed = 150;
PitchSpeed = 17;
RollSpeed = 10;
YawSpeed = 10;
Acceleration = 20;
StartUpTime = 5;
ThrottleUp = Enum.KeyCode.LeftShift;
ThrottleDown = Enum.KeyCode.LeftControl;
PitchUp = Enum.KeyCode.S;
PitchDown = Enum.KeyCode.W;
RollLeft = Enum.KeyCode.A;
RollRight = Enum.KeyCode.D;
YawLeft = Enum.KeyCode.Q;
YawRight = Enum.KeyCode.E;
LandingGear = Enum.KeyCode.G;
Exit = Enum.KeyCode.E;
}
return Config
I also have tried to set CanWork to true but not changes.