Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Car Spawner (Cloned Car rename to Players Name)?

Hello! im scripting an Car Spawner. But im not sure why the script is not working.

I want make, that if you click at the button, that a cloned car from the ServerStorage the Name from the player has (Owner).

May someone can help me

My script:

local Button = script.Parent.Parent.Button
local player = game:GetService("Players").localPlayer
 
Button.MouseButton1Click:Connect(function()
local enabled = false
if enabled == false then
		enabled = true
 		local Mod = game.ServerStorage['AudiS3']
 		local clone = Mod:clone()
 		clone.Parent = workspace
 		clone:MakeJoints()
		clone.Name = player.Name.. "s AudiS3"
 		wait(15)
 		enabled = false
 	end
end)

1 comment

0

The Car Spawns currently with the Name "AudiS3" in the Workspace. And if im set the (Clone.Name = player.Name.. "s AudiS3") over the (Clone.Parent = workspace), then the car dosnt spawn

1 answer

✓ Accepted answer

You cannot access ServerStorage from a LocalScript! What you will need to do is create a RemoteEvent in ReplicatedStorage called "SpawnCar".

Then in your local script:

local Button = script.Parent.Parent.Button
local player = game:GetService("Players").localPlayer
local Event = game.ReplicatedStorage.SpawnCar

Button.MouseButton1Click:Connect(function()
local enabled = false
if enabled == false then
        enabled = true
        Event:FireServer()
        wait(15)
        enabled = false
    end
end)

Create a server script called "SpawnCar"

local Event = game.ReplicatedStorage.SpawnCar

Event.OnServerEvent:Connect(function(player)
        local Mod = game.ServerStorage['AudiS3']
        local clone = Mod:clone()
        clone.Parent = workspace
        clone:MakeJoints()
        clone.Name = player.Name.. "s AudiS3"
end)

1 comment

0

Thats it, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.