Hey there! So I’ve decided to begin working on a story game and while testing out the teleporting script to the story, it errors “Unable to cast value to object”
This is the script
local truck = game.Workspace.Chapter1Lobby.Chapter1Truck
local Seats = truck.Chapter1TeleportSeats:GetChildren()
local exitGui = script.Parent:FindFirstChild("ExitButton")
local debounce = false
local event = game.ReplicatedStorage:WaitForChild("SendPlayersToChapter1")
local loadingscreen = script.Parent:FindFirstChild("LoadingScreen")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
for i, emptySeat in pairs(Seats) do
if emptySeat.Occupant == nil then
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0
player.Character.HumanoidRootPart.CFrame = Seats[math.random(1,#Seats)].CFrame
exitGui:Clone().Parent = player.PlayerGui
break
end
end
event.Event:Connect(function(place)
debounce = true
wait(0.1)
player.PlayerGui.ExitButton:Destroy()
loadingscreen:Clone().Parent = player.PlayerGui
player.Character.Humanoid.JumpPower = 50
wait(0.2)
player.Character.Humanoid.Jump = true
wait(0.2)
player.Character.Humanoid.JumpPower = 50
wait(0.2)
local plrs = {}
for i, v in pairs(Seats) do
if v.Occupant == true then
local plr = game.Players:GetPlayerFromCharacter(v.Occupant.Parent)
table.insert(plrs, plr)
end
end
local tpService = game:GetService("TeleportService")
local code = tpService:ReserveServer(place)
tpService:TeleportToPlaceInstance(place, code, plrs) -- the error code
debounce = false
end)
end
end)
Can anyone help me figure out what is going on here? Thanks!