Hello. Whenever you go ahead and try to spawn a car, it gives an error that there’s an index error with :Clone().
Error:
Players.TheKman2019.PlayerGui.Civ_Car_Spawn.Main.VehicleInfo.Spawn.CarspawnScript:5: attempt to index nil with 'Clone'
Script:
script.Parent.MouseButton1Up:Connect(function(player)
local SelectedCar = game.ReplicatedStorage.CarSystem.SelectedCar.Value
local Car = SelectedCar
local CloneCar = Car:Clone()
local Position1 = game.Workspace["Civilian Spawn"].CarSpots.S1.Position
local Position2 = game.Workspace["Civilian Spawn"].CarSpots.S2.Position
local Position3 = game.Workspace["Civilian Spawn"].CarSpots.S3.Position
local Position4 = game.Workspace["Civilian Spawn"].CarSpots.S4.Position
local Position5 = game.Workspace["Civilian Spawn"].CarSpots.S5.Position
local PossibleSpawns = {Position1, Position2, Position3, Position4, Position5}
local Car = SelectedCar
if Car then
else
print("Car not selected")
end
CloneCar.Parent = game.Workspace
CloneCar.PrimaryPart = CloneCar.Primary
CloneCar:SetPrimaryPartCFrame(CFrame.new(PossibleSpawns[math.random(1, #PossibleSpawns)]))
game.ReplicatedStorage.PlayerSpawnedCar:FireServer(player)
script.Parent.Parent.Enabled = false
end)
i have an question tho why do you have 2 locals car and why is the selectedcar an server value cuz if another player clicks (just an example sorry) it will change but if you clicked after a few seconds you will get that player car (IF that is the fully script of the mousebutton1up)
but yeah thats weird
The value is set from the client and read from the server. I really don’t know how you can spawn a car on the client side because then the car would be invisible to all other players no?
ok then you should aswell fire the car so that it uhh
appears for others if it can find?
but yeah you should rescript so that in the client when you mouse1up thingie you fire the selectedcarvalue and the serverscript will do its stuff
i can show you an example if you didnt get what i said
Sorry for the late response, here’s my progress so far. It’s giving an error for SetPrimaryPartCFrame which was never an error when this even worked in the past.
Client:
script.Parent.MouseButton1Up:Connect(function(player)
local SelectedCar = game.ReplicatedStorage.CarSystem.SelectedCar.Value
print(SelectedCar)
game:GetService("ReplicatedStorage").VehicleSpawnRequest:FireServer(SelectedCar)
end)
Server:
local RS = game:GetService("ReplicatedStorage")
RS.VehicleSpawnRequest.OnServerEvent:Connect(function(SelectedCar, player)
local Car = SelectedCar
local CloneCar = Car:Clone(player)
local Position1 = game.Workspace["Civilian Spawn"].CarSpots.S1.Position
local Position2 = game.Workspace["Civilian Spawn"].CarSpots.S2.Position
local Position3 = game.Workspace["Civilian Spawn"].CarSpots.S3.Position
local Position4 = game.Workspace["Civilian Spawn"].CarSpots.S4.Position
local Position5 = game.Workspace["Civilian Spawn"].CarSpots.S5.Position
local PossibleSpawns = {Position1, Position2, Position3, Position4, Position5}
if Car then
else
print("Car not selected")
end
CloneCar.Parent = game.Workspace.Vehicles
CloneCar:SetPrimaryPartCFrame(CFrame.new(PossibleSpawns[math.random(1, #PossibleSpawns)]))
end)
There is no other answer than just SelectedCar is nil.
Is the button script on the server (script), but you changed the value/selection on the client (local script)?
If so, it’s not replicating and thus leaving CarSystem.SelectedCar with a value of nil. You can check this by selecting a car and then swapping the view to server via the Test ribbon tab.
Also, if this button script is a normal server script, then not much else in the code will work.