Motor Car spawning at an incorrect location

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to make a “Motor Vehicle” Spawner.

  2. What is the issue? Include screenshots / videos if possible!
    robloxapp-20240529-1122278.wmv (2.4 MB)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked all over the DevForum, and I can’t find a solution.

Script:

local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")

local MotorSpawnerTool = script.Parent


local _Function = MotorSpawnerTool:FindFirstChild("RemoteFunction")

MotorSpawnerTool.Equipped:Connect(function(_mouse)
	local Character = MotorSpawnerTool.Parent
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local Player = Players:GetPlayerFromCharacter(Character)
	
	MotorSpawnerTool.Activated:Connect(function()
		if not MotorSpawnerTool.Debounce.Value then
			MotorSpawnerTool.Debounce.Value = true
			local Motor = InsertService:LoadAsset(14362437183):GetChildren()[1]
			Motor.Parent = workspace
			Motor:PivotTo(CFrame.new(_mouse.Hit.Position) * CFrame.fromEulerAnglesXYZ(0, math.rad(Character.PrimaryPart.Orientation.Y), 0))
			local vehicleSeat = Instance.new("VehicleSeat")
			vehicleSeat.Parent = Motor
			vehicleSeat.TopSurface = Enum.SurfaceType.Smooth
			vehicleSeat.BottomSurface = Enum.SurfaceType.Smooth
			vehicleSeat.Size = Vector3.new(2, 0.25, 2)
			vehicleSeat.BrickColor = BrickColor.new("Black")
			local vehicleSeatWeld = Instance.new("Weld")
			vehicleSeatWeld.C0 = CFrame.new(0, -0.125, 0)
			vehicleSeatWeld.C1 = CFrame.new(-1, 0.125, -1.25)
			vehicleSeatWeld.Parent = vehicleSeat
			vehicleSeatWeld.Part0 = vehicleSeat
			vehicleSeatWeld.Part1 = Motor.PrimaryPart
			local Seat1 = Instance.new("VehicleSeat")
			Seat1.Parent = Motor
			Seat1.TopSurface = Enum.SurfaceType.Smooth
			Seat1.BottomSurface = Enum.SurfaceType.Smooth
			Seat1.Size = Vector3.new(2, 0.25, 2)
			Seat1.BrickColor = BrickColor.new("Black")
			local SeatWeld1 = Instance.new("Weld")
			SeatWeld1.C0 = CFrame.new(0, -0.125, 0)
			SeatWeld1.C1 = CFrame.new(1, 0.125, -1.25)
			SeatWeld1.Parent = Seat1
			SeatWeld1.Part0 = Seat1
			SeatWeld1.Part1 = Motor.PrimaryPart
			wait(1.5)
			MotorSpawnerTool.Debounce.Value = false
		end
	end)
end)

Hello, this is my fix for the issue, I use ‘SetPrimaryPartCFrame’ instead of ‘PivotTo’. If you have any questions make sure you ask!

--|< Services >|--
local Players = game:GetService("Players");
local InsertService = game:GetService("InsertService");

--|< Tool >|--
local MotorSpawnerTool = script.Parent;
local debounce = MotorSpawnerTool:FindFirstChild("Debounce");

--|< Connections >|--
MotorSpawnerTool.Equipped:Connect(function(_mouse)
    local Character = MotorSpawnerTool.Parent;

    MotorSpawnerTool.Activated:Connect(function()
        if not debounce.Value then
            debounce.Value = true;
            local Motor = InsertService:LoadAsset(14362437183):GetChildren()[1];
            Motor.Parent = workspace;

            local spawnPosition = _mouse.Hit.Position;

            Motor:SetPrimaryPartCFrame(CFrame.new(spawnPosition));

            local vehicleSeat1 = Instance.new("VehicleSeat", Motor);
            vehicleSeat1.TopSurface = Enum.SurfaceType.Smooth;
            vehicleSeat1.BottomSurface = Enum.SurfaceType.Smooth;
            vehicleSeat1.Size = Vector3.new(2, 0.25, 2);
            vehicleSeat1.BrickColor = BrickColor.new("Black");
            local seatWeld1 = Instance.new("Weld", vehicleSeat1);
            seatWeld1.Part0 = vehicleSeat1;
            seatWeld1.Part1 = Motor.PrimaryPart;
            seatWeld1.C0 = CFrame.new(0, -0.125, 0) * CFrame.new(-1, 0.125, -1.25);

            local vehicleSeat2 = Instance.new("VehicleSeat", Motor);
            vehicleSeat2.TopSurface = Enum.SurfaceType.Smooth;
            vehicleSeat2.BottomSurface = Enum.SurfaceType.Smooth;
            vehicleSeat2.Size = Vector3.new(2, 0.25, 2);
            vehicleSeat2.BrickColor = BrickColor.new("Black");
            local seatWeld2 = Instance.new("Weld", vehicleSeat2);
            seatWeld2.Part0 = vehicleSeat2;
            seatWeld2.Part1 = Motor.PrimaryPart;
            seatWeld2.C0 = CFrame.new(0, -0.125, 0) * CFrame.new(1, 0.125, -1.25);

            task.wait(1.5);
            debounce.Value = false;
        end
    end)
end)

It says “This mouse is no longer active”, and it’s still not spawning at the correct location.

There isn’t anything here to place the vehicle. It just creates a seat and welds it to the Motor.PrimaryPart.

Where is the script that gives a location for the car?
Where in the script is it getting the mouse location? The error in the Output window should tell you the location, name, and error line in the script.

– Issues –

Image:

Script:

-- Services --
local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")

-- Tool --
local MotorSpawnerTool = script.Parent
local debounce = MotorSpawnerTool:FindFirstChild("Debounce")

-- Connections --
MotorSpawnerTool.Equipped:Connect(function(_mouse)
	local Character = MotorSpawnerTool.Parent

	MotorSpawnerTool.Activated:Connect(function()
		if not debounce.Value then
			debounce.Value = true
			local Motor = InsertService:LoadAsset(14362437183):GetChildren()[1]
			Motor.Parent = workspace

			local spawnPosition = _mouse.Hit.Position
			
			local Seat1 = Instance.new("VehicleSeat", Motor)
			Seat1.TopSurface = Enum.SurfaceType.Smooth
			Seat1.BottomSurface = Enum.SurfaceType.Smooth
			Seat1.Size = Vector3.new(2, 0.25, 2)
			Seat1.BrickColor = BrickColor.new("Black")
			local seatWeld1 = Instance.new("Weld", Seat1)
			seatWeld1.Part0 = Seat1
			seatWeld1.Part1 = Motor.PrimaryPart
			seatWeld1.C0 = CFrame.new(0, -0.125, 0)
			seatWeld1.C1 = CFrame.new(-1, 0.125, -1.25)

			local Seat2 = Instance.new("Seat", Motor)
			Seat2.TopSurface = Enum.SurfaceType.Smooth
			Seat2.BottomSurface = Enum.SurfaceType.Smooth
			Seat2.Size = Vector3.new(2, 0.25, 2)
			Seat2.BrickColor = BrickColor.new("Black")
			local seatWeld2 = Instance.new("Weld", Seat2)
			seatWeld2.Part0 = Seat2
			seatWeld2.Part1 = Motor.PrimaryPart
			seatWeld2.C0 = CFrame.new(0, -0.125, 0)
			seatWeld2.C1 = CFrame.new(1, 0.125, -1.25)
			
			task.wait(1.5)
			debounce.Value = false
		end
	end)
end)

But you aren’t posting the DataStores script that gets the mouse.Position and sends the error in line 2.

Why insert the model using InsertService? Just put it into ServerStorage, then Clone it and spawn it into the game from there. Otherwise you are lagging the game because you are getting the asset from Roblox, not your game.

In your script you parent Motor to the workspace so it’s probably ending up at whatever Position the original Model was created when you built it.
Then you set the variable spawnPosition = _mouse.Hit.Position, but I don’t see it the variable used anywhere in the script after that to position the model.
When you do finally get the mouse Position number set it 1st, and after that parent the Motor to the workspace instead of the way you are doing it.

Also, why are you creating the Seats within the script? Just include them in the Motor model to begin with and spawn the entire Model in? Your way seems like a lot of extra work.

I almost got the solution already.

Client:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()

local InsertService = game:GetService("InsertService")

local MotorSpawnerTool = script.Parent

local _Function = MotorSpawnerTool:FindFirstChild("RemoteFunction")

MotorSpawnerTool.Activated:Connect(function()
	_Function:InvokeServer(Mouse.Hit.Position)
end)

Server:

-- Services --
local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")

-- Tool --
local MotorSpawnerTool = script.Parent
local debounce = MotorSpawnerTool:FindFirstChild("Debounce")
local _Function = MotorSpawnerTool:FindFirstChild("RemoteFunction")

-- Connections --
function SpawnMotor(player, spawnPosition)
	local character = player.Character or player.CharacterAdded:Wait()
	
	local Motor = InsertService:LoadAsset(14362437183):GetChildren()[1]
	Motor.Parent = workspace

	local Seat1 = Instance.new("VehicleSeat", Motor)
	Seat1.TopSurface = Enum.SurfaceType.Smooth
	Seat1.BottomSurface = Enum.SurfaceType.Smooth
	Seat1.Size = Vector3.new(2, 0.25, 2)
	Seat1.BrickColor = BrickColor.new("Black")
	local seatWeld1 = Instance.new("Weld", Seat1)
	seatWeld1.Part0 = Seat1
	seatWeld1.Part1 = Motor.PrimaryPart
	seatWeld1.C0 = CFrame.new(0, -0.125, 0)
	seatWeld1.C1 = CFrame.new(-1, 0.125, -1.25)

	local Seat2 = Instance.new("Seat", Motor)
	Seat2.TopSurface = Enum.SurfaceType.Smooth
	Seat2.BottomSurface = Enum.SurfaceType.Smooth
	Seat2.Size = Vector3.new(2, 0.25, 2)
	Seat2.BrickColor = BrickColor.new("Black")
	local seatWeld2 = Instance.new("Weld", Seat2)
	seatWeld2.Part0 = Seat2
	seatWeld2.Part1 = Motor.PrimaryPart
	seatWeld2.C0 = CFrame.new(0, -0.125, 0)
	seatWeld2.C1 = CFrame.new(1, 0.125, -1.25)

	local Seat3 = Instance.new("Seat", Motor)
	Seat3.TopSurface = Enum.SurfaceType.Smooth
	Seat3.BottomSurface = Enum.SurfaceType.Smooth
	Seat3.Size = Vector3.new(2, 0.25, 2)
	Seat3.BrickColor = BrickColor.new("Black")
	local seatWeld3 = Instance.new("Weld", Seat3)
	seatWeld3.Part0 = Seat3
	seatWeld3.Part1 = Motor.PrimaryPart
	seatWeld3.C0 = CFrame.new(0, -0.125, 0)
	seatWeld3.C1 = CFrame.new(-1, 0.125, 2.25)

	local Seat4 = Instance.new("Seat", Motor)
	Seat4.TopSurface = Enum.SurfaceType.Smooth
	Seat4.BottomSurface = Enum.SurfaceType.Smooth
	Seat4.Size = Vector3.new(2, 0.25, 2)
	Seat4.BrickColor = BrickColor.new("Black")
	local seatWeld4 = Instance.new("Weld", Seat4)
	seatWeld4.Part0 = Seat4
	seatWeld4.Part1 = Motor.PrimaryPart
	seatWeld4.C0 = CFrame.new(0, -0.125, 0)
	seatWeld4.C1 = CFrame.new(1, 0.125, 2.25)

	Motor:PivotTo(CFrame(spawnPosition) * CFrame.fromEulerAnglesXYZ(0, math.rad(character.PrimaryPart.Orientation.Y), 0))
	Seat1:Sit(character:FindFirstChildOfClass("Humanoid"))
end


MotorSpawnerTool.Equipped:Connect(function(_mouse)
	_Function.OnServerInvoke = SpawnMotor
end)

Issue:

Players.dwightcar.Backpack.Motor Spawner.Script:61: attempt to call a table value - Client - LocalScript:13

robloxapp-20240529-1559520.wmv (2.0 MB)

New error: This Mouse is no longer active - Server - Script:13

-- Services --
local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")

-- Tool --
local MotorSpawnerTool = script.Parent
local debounce = MotorSpawnerTool:FindFirstChild("Debounce")
local _Function = MotorSpawnerTool:FindFirstChild("RemoteFunction")

-- Connections --
MotorSpawnerTool.Equipped:Connect(function(_mouse)
	MotorSpawnerTool.Activated:Connect(function()
		local Spawn_Position = _mouse.Hit.Position
		if not debounce.Value then
			debounce.Value = true
			local Motor = InsertService:LoadAsset(14362437183):GetChildren()[1]
			Motor.Parent = workspace
			Motor:PivotTo(CFrame.new(Spawn_Position))
			wait(1.5)
			debounce.Value = false
		end
	end)
end)

Update: I think I found the solution.

Server:

local InsertService = game:GetService("InsertService")


local MotorSpawnerTool = script.Parent


MotorSpawnerTool.Equipped:Connect(function(_mouse)
	MotorSpawnerTool.RemoteFunction.OnServerInvoke = function(player, Position)
		if not MotorSpawnerTool.Debounce.Value then
			MotorSpawnerTool.Debounce.Value = true
			local Motor = InsertService:LoadAsset(14362437183):GetChildren()[1]
			Motor.Parent = workspace
			Motor:PivotTo(CFrame.new(Position))
			wait(1.5)
			MotorSpawnerTool.Debounce.Value = false
		end
	end
end)

Client:

local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local MotorSpawnerTool = script.Parent

MotorSpawnerTool.Activated:Connect(function()
	MotorSpawnerTool.RemoteFunction:InvokeServer(Mouse.Hit.Position)
end)
1 Like

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