Struggling with teleporting a model out of another part to a different location

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

The collision script is controlled by the kart itself, not by the player.

you can also try

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

every 0.5 seconds (configurable) it will check for collisions and check if it has to move the kart

That seems like it’d be somewhat heavy on performance

also that was using a system demonstrated by the player, which you could change to make it compatible with your script

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

The network owner has to be a player or else the collision doesn’t work at all. I’ve said this already.

Keep the network owner as the player nevermind, but try the script

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.

If there’s no player in the kart it’ll delete itself.

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

Have you tried doing this, it doesn’t change too much about your script.

It changes almost every aspect of the script

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

Sorry for wasting your time

Sometimes all we need is a few minutes away, all good man

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.