Hello!
I've run into an issue while working on a new system. The goal is to be able to clone a vehicle from ServerStorage into the game. However, this vehicle should only show up locally- as it serves as a preview within the dealership. If it is server-wide, then the vehicles will be replicated across all clients created a mess of vehicles in the same exact spot.
To combat this, I wrote the following two scripts. One is a LocalScript that sets up the vehicle preview page, the other is a server script in ServerScriptStorage that handles client to server events.
LocalScript
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() local reference = script.Parent.Parent.Name --this script is in a button, and the name of the button is the reference for the model game.ReplicatedStorage.Events.dealershipPreview:FireServer(reference, "SETUP") --this section of code is supposed to set up the local preview car. local preview = game.ReplicatedStorage.vehicleQueue:WaitForChild(player.name.."_car"):Clone() wait(2) preview.Parent = game.Workspace preview:SetPrimaryPartCFrame((workspace.Dealership.Preview.Preview.CFrame + Vector3.new(0,4,0)) * CFrame.Angles(math.rad(90),0,math.rad(90))) player.PlayerGui.Dealership.Dealer.Visible = false player.PlayerGui.Dealership.PreviewPage.Visible = true
ServerScript
game.ReplicatedStorage.Events.dealershipPreview.OnServerEvent:Connect(function(player,data) if data == "SETUP" then local car = game.ServerStorage.Vehicles.Civillian[data]:Clone() car.Parent = game.ReplicatedStorage.vehicleQueue car.Name = player.Name.."_car"
This works, as in it replicates the vehicle, then clones it locally. However, the model hasn't finished loading by the time the LocalScript clones the new vehicle in game.ReplicatedStorage.dealershipQueue
. I've tried using things such as :WaitForChild()
or a simple conditional however none of these worked. How can I ensure that the entire vehicle is loaded in before cloning the vehicle locally? From my research, I've seen some developers recommend using the RunService
, but I have yet to find an explanation of how to utilize it. Any help or guides is super appreciated. Thanks!