Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Car not working when spawned in using script?

Asked by 4 years ago

When its in the workspace, it works perfectly. When I spawn it in using a script, it doesn't work. I have the car in the serverstorage, in a "Cars" folder.

001--DriveScript
002local ServerStorage = game:GetService("ServerStorage")
003local Car = ServerStorage.Cars.Car
004local vehicleSeat = Car.Base.VehicleSeat
005 
006local motorFR = Car.WheelFR:FindFirstChildWhichIsA("CylindricalConstraint", true)
007local motorFL = Car.WheelFL:FindFirstChildWhichIsA("CylindricalConstraint", true)
008local motorBR = Car.WheelBR:FindFirstChildWhichIsA("CylindricalConstraint", true)
009local motorBL = Car.WheelBL:FindFirstChildWhichIsA("CylindricalConstraint", true)
010 
011local springFR = Car.WheelFR:FindFirstChildWhichIsA("SpringConstraint", true)
012local springFL = Car.WheelFL:FindFirstChildWhichIsA("SpringConstraint", true)
013local springBR = Car.WheelBR:FindFirstChildWhichIsA("SpringConstraint", true)
014local springBL = Car.WheelBL:FindFirstChildWhichIsA("SpringConstraint", true)
015 
View all 108 lines...

Next Script

01--CarSpawner
02local ServerStorage = game:GetService("ServerStorage")
03local ReplicatedStorage = game:GetService("ReplicatedStorage")
04local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")
05local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
06 
07SpawnCarEvent.OnServerEvent:Connect(function(player, carName)
08    local Car = ServerStorage:FindFirstChild("Cars"):FindFirstChild(carName)
09    if Car then
10        local clonedCar = Car:Clone()
11        clonedCar.Name = player.Name .. 'sCar'
12        clonedCar.Parent = game.Workspace
13        clonedCar:MoveTo(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * 15)
14    end
15end)
View all 37 lines...

I can provide the delete and call scripts if needed.

0
Errors errors please are there any errors in the output? those are 130 lines and there might be more reasons. Please check the output imKirda 4491 — 4y
0
Ok, I figured out why. The script spawns the car into Workspace, with the name "playername'sCar'. For example, mcslimemansCar. How would I make 003 local Car = ServerStorage.Cars.Car into something like 003 local Car = workspace.playernamesCar ? mcslimeman 37 — 4y
0
Also, there are no errors in the output mcslimeman 37 — 4y
0
mhm you need to get the player and then do this: workspace[player.Name.."'Cat"]. It will look for your car then. imKirda 4491 — 4y
View all comments (2 more)
0
ok, how would i get the player? mcslimeman 37 — 4y
0
The scripts are on a normal script. mcslimeman 37 — 4y

Answer this question