I was just getting a basis down, in the full system you already have the player that owns the kart, so teleporting the kart and the player should be easy enough
The biggest thing that bothers me about the one I made is having to specify the parts in the workspace individually in a table, but the way .Touched works kinda sucks
while wait(0.5) do
local connection = kart.Touched:Connect(function() end)
local parts = kart:GetTouchingParts()
connection:Disconnect()
for i,part in ipairs(parts) do
local boxParent = part.Parent
local outOfBounds = boxParent:FindFirstChild("COL_BOUNDARY")
if outOfBounds then
if isFloating == false then
isFloating = true
kart.HitSound:Play()
driverPlayer.PlayerGui.RaceHUD.ScreenFade.OOBAnimation:FireClient(driverPlayer) --This line isn't really important, it just fires the UI animation for driving out of bounds.
kart.Parent.PrimaryPart = kart
wait(0.5)
kart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
kart.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
kart.Parent:PivotTo(respawnCFrame)
kart.Anchored = true
wait(1)
kart.Anchored = false
kart.Parent.PrimaryPart = nil
isFloating = false
end
end
end
end
Then you could just apply the same principle to the one inside the kart, and use the script.Parent to specify the kart itself. just change the part to if the part is the kart touching it like floof said
It’s not heavy on the performance as long as you don’t have 100 karts. As long as the network owner is equal to nil (basically the server) you should be fine
Also for smoother performance with the player server-side, you should set the NetworkOwnership of the vehicle to the player that entered, and when they leave set it to nil
This is from the network ownership docs
local Players = game:GetService("Players")
local vehicleSeat = script.Parent
vehicleSeat.Changed:Connect(function(prop)
if prop == "Occupant" then
local humanoid = vehicleSeat.Occupant
if humanoid then
-- Get the player from the character
local player = Players:GetPlayerFromCharacter(humanoid.Parent)
if player then
vehicleSeat:SetNetworkOwner(player)
end
else
-- Reset ownership when seat is unoccupied
vehicleSeat:SetNetworkOwnershipAuto()
end
end
end)
I’d have to rewrite the entire script from scratch in order for this to work as the function used for OOB detection is the same one used for various other things. I feel like it’d be way easier to just find a way to move the kart out of the box using physics.
You can just remove the part of the script that says local function col(box) and the kart.Touched:Connect(col) and replace it with the while wait loop i made
okay, but you should still set the ownership of the kart to the player when they sit in it because it will make sure that the player will have a more responsive vehicle controller
Managed to solve it by setting kart.CanTouch to false before teleporting the kart and then setting it back to true after the process finishes, thought about it during a shower and now I feel dumb for blowing this way out of proportion