There are Two Main reasons as to why this would happen.
- The first reason being that your
Vehicle is already floating in the Workspace
What do I mean by that? When you put a Model or a Part in Workspace, it automatically puts it at the center of the Workspace. The thing about the Clone() feature is that it will clone to that specific part if the script hasn't actually told the model to move somewhere.
Example.
- Say you have a
Car Model at 0, 0, 0.
- You then moved it up thinking that if it is down, it will go through the
Workspace.
- You run your script and the
Model is up.
It is always a good Idea to check whether this is your case. If not then let's move on.
- The second reason being that you have
Anchored your Vehicle in the Workspace.
Anchoring is a big no-no for a Vehicle. A Vehicle cannot move if it is Anchored and will simply stay on one position if so. Which is why this is a follow through of my first point.
Check if your Model is at the right Position that you want and is not Anchored.
- **If error still persists, then you could manually set the location of the
Vehicle by simply utilizing MoveTo().**
MoveTo() is a feature designed for Models to move the Model freely around the Workspace.
MoveTo() takes in Vector3 values and just positions like any other parts.
local Vector3New = Vector3.new;
NewCar:MoveTo(Vector3New(100, 0, 0));
- If that is not your case too then you would want to check the output. There could be an error which could be stopping your code.
Here is my working code. Feel free to change it up to your desire.
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Workspace = game:GetService("Workspace");
local Player = game:GetService("Players").LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local PlayerGui = Player:WaitForChild("PlayerGui");
local Car = ReplicatedStorage:WaitForChild("Car");
local CaSpawningGui = PlayerGui:WaitForChild("CarSpawningGui");
local Button = CaSpawningGui:WaitForChild("Button");
local Head = Character["Head"];
local NewCar;
local Vector3New = Vector3.new;
local function SpawnGuiWhenClicked ()
print("Envoked function");
NewCar = Car:Clone();
NewCar.Parent = Workspace;
NewCar:MoveTo(Vector3New(10, 0, 0));
NewCar:MakeJoints();
NewCar.PrimaryPart = NewCar.DriveSeat;
NewCar:SetPrimaryPartCFrame(Head.CFrame);
if Workspace:FindFirstChild("Car") then print("Found") end;
end;
Button.MouseButton1Down:Connect(SpawnGuiWhenClicked);
####Should you have any questions, feel free to comment below. Have fun debugging.
4 comments
It could possibly be due to the fact that the car is anchored?
I read your comment. Yes I know that it is in Replicated Storage. But you first want to put it in Workspace, position your model properly THEN put it in Replicated Storage.
gmatch i tried it anchored and unanchored ad they both do the exact same
If you actually read my whole code, then you would see that I wrote use
MoveTo()if it still errors. Either give me a youtube video or a uncopylocked version.