Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Model doesn't clone in ReplicatedStorage?

Asked by 4 years ago

I tried to make a car spawner for my drifting game but I'm facing a problem. The car doesn't clone in ReplicatedStorage. I'm also using a remote event.

--local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local button = script.Parent
local shopframe = script.Parent.Parent
local designframe = shopframe.Parent.ShopFrame
local openbutton = shopframe.Parent.OpenShop

local event = ReplicatedStorage.Events.SpawnCar
local cars = ReplicatedStorage.Cars

button.MouseButton1Click:Connect(function()
    cars.Nissan350z:Clone() 
    wait(0.1) --//makes sure it clones before firing the server
    event:FireServer(cars.Nissan350z)
    shopframe.Visible = false
    designframe.Visible = false
    openbutton.Text = "Open Shop"
end)
--server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event = ReplicatedStorage.Events.SpawnCar

event.OnServerEvent:Connect(function(player, car)
    car.Parent = game.Workspace
end)

2 answers

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
4 years ago

Hey, ItsAntonio_xD!

The first thing I noticed was you're cloning the car on the client, which means it won't replicate to the server. You have to clone the car in the event so that it can replicate it.

Your normal script that has the remote event should look something like this:

--server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event = ReplicatedStorage.Events.SpawnCar

event.OnServerEvent:Connect(function(player, car)
    local clonecar = car:Clone()
    clonecar.Parent = workspace
end)

For the localscript, you can pass the car model as the argument.

--local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local button = script.Parent
local shopframe = script.Parent.Parent
local designframe = shopframe.Parent.ShopFrame
local openbutton = shopframe.Parent.OpenShop

local event = ReplicatedStorage.Events.SpawnCar
local cars = ReplicatedStorage.Cars

button.MouseButton1Click:Connect(function()
    event:FireServer(cars.Nissan350z)
    shopframe.Visible = false
    designframe.Visible = false
    openbutton.Text = "Open Shop"
end)
0
Thank you, it worked perfectly! antvvnio 40 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

The client does not replicate to the server. The client does not replicate to the server Simple fix: Just clone and parent the car server-side Also make sure your remoteevent has some cooldown so some person can't spam click the button

--The local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local button = script.Parent
local shopframe = script.Parent.Parent
local designframe = shopframe.Parent.ShopFrame
local openbutton = shopframe.Parent.OpenShop

local event = ReplicatedStorage.Events.SpawnCar
local cars = ReplicatedStorage.Cars

button.MouseButton1Click:Connect(function()
    event:FireServer(cars.Nissan350z)
    shopframe.Visible = false
    designframe.Visible = false
    openbutton.Text = "Open Shop"
end)
--The server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event = ReplicatedStorage.Events.SpawnCar

event.OnServerEvent:Connect(function(player, car)
    ReplicatedStorage.Cars["Nissan350z"]:Clone().Parent = workspace --game.Workspace works too, workspace is faster to type
end)

Let me know if this helps! :)

Answer this question