Cant spawn object when clicking GUI

Hi! I want to make a gui button that spawns a car when clicked. when i spawn it the car looks like this:

but if i place it right in the workspace it looks like this:

car name is Aerox c
script for spawning car:

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)

try something like

local car = carfld["Aerox C"]:Clone()
car:MakeJoints()
car.Parent = workspace

is the car also getting welded maunually or is it getting welded by a script?

I took a toolbox because I couldn’t model a car. i dont have Blender, but I will see it in the scripts

do objects in folders not clone?

everything can be cloned inside a folder

yes i realised that. i would try watching a video

i think its because im cloning in the local script. I dont know how to use remote events properly

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.

that worked thanks! what would exploiters do in a cloning script anyway?

They can send the name of the vehicle they do not own by sending manipulated data.

ohk thanks for the info. ill use some anti hack script maybe or will put it in some safe place

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.