local button = script.Parent
local carfld = game.ReplicatedStorage.Cars
button.MouseButton1Click:Connect(function(plr)
local plr = game.Players.LocalPlayer
local car = carfld["Aerox C"]:Clone()
car.Parent = workspace
end)
Create RemoteEvent inside of ReplicatedStorage. (Name it like SpawnCar)
Client Side Script:
local button = script.Parent
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- replace with ur RemoteEvent Name
local db = true
button.MouseButton1Click:Connect(function()
if db == false then return end
db = false
remote:FireServer("Aerox C") -- data
task.wait(2) -- cooldown
db = true
end)
Server Side Script (Supposed to be in ServerScriptService):
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- replace with ur RemoteEvent Name
local carfld = game:GetService("ReplicatedStorage"):WaitForChild("Cars")
remote.OnServerEvent:Connect(function(player, data)
local car = carfld:FindFirstChild(data)
if not car then warn(`couldn't find {data}`) return end
local clone = car:Clone()
clone.Parent = workspace
end)
However, I do not recommend sending data from the client to the server, as this allows exploiters to send arbitrarily manipulated data.