In these two scripts, the client looks at a folder in replicated storage called “OwnedCars” which is filled with the players owned cars which are cloned to the folder by another local script.
The client then creates a button for each owned car with a specific ObjectValue child connected to the cars, if the player clicks the button it will send the ObjectValue over to the server to be cloned. However, the server seems to not acknowledge its existence.
Client:
local GUI = script.Parent
local garageFrame = GUI.UIFrame.GarageFrame
local openAndCloseButton = GUI.OpenAndCloseButton
local cars = game.ReplicatedStorage.OwnedCars
local spawnUIButton = game.ReplicatedStorage.UI.SpawnButton
local spawnCarEvent = game.ReplicatedStorage.Events.SpawnCar
local function updateCars()
for _, child in pairs(garageFrame:GetChildren()) do
if child:IsA("GuiObject") and child.Name == spawnUIButton.Name then
child:Destroy()
end
end
for i, v in pairs(cars:GetChildren()) do
local clonedSpawnButton = spawnUIButton:Clone()
clonedSpawnButton.Parent = garageFrame
clonedSpawnButton:FindFirstChild("Car").Value = v
clonedSpawnButton.Text = "Spawn " .. clonedSpawnButton:FindFirstChild("Car").Value.Name
clonedSpawnButton.MouseButton1Down:Connect(function ()
print(clonedSpawnButton.Car.Value)
spawnCarEvent:FireServer(clonedSpawnButton.Car.Value, cars)
end)
end
end
openAndCloseButton.MouseButton1Down:Connect(function ()
updateCars()
GUI.UIFrame.Visible = not GUI.UIFrame.Visible
end)
prints the objectvalue with no problem at all
Server:
local spawnCarEvent = game.ReplicatedStorage.Events.SpawnCar
local function spawnCar(player, carValue, cars)
--for i, v in pairs(cars) do
-- if v:GetAttribute("PlayerId") == player.UserId then
-- v:Destroy()
-- end
--end
print(carValue)
local car = carValue
local clonedCar = car:Clone()
print("cloned car : " .. clonedCar.Name)
clonedCar:SetAttribute("PlayerId", player.UserId)
if clonedCar:GetAttribute("Colorable") == true then
clonedCar:FindFirstChild("Body").BrickColor = BrickColor.random()
end
clonedCar.Parent = workspace.Cars
clonedCar:MoveTo(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector + Vector3.new(5, 0,0))
end
spawnCarEvent.OnServerEvent:Connect(function (plr, carValue, carsFolder)
spawnCar(plr, carValue, carsFolder)
end)
If you want to know anymore information, im here to reply as im desperate to stop this problem.