Hi there, I am trying to make this work as my vehicle requires a vehicle that can be easily accessed by game.workspace. Can you see what I have done wrong and help me resolve it
script.Parent.MouseButton1Click:Connect(function(player)
local car = game.ServerStorage.E200MMC:Clone()
car.Parent = workspace
car.Name = car..player.Name
end)
I am trying to spawn a vehicle which has a different name every time it’s spawned as it is supposed to makes it easier for me to develop the vehicle as most stuff are in the vehicle, not as a Gui. An example is once it’s spawned, the model name should be vehicle-builderman
local times = 0
script.Parent.MouseButton1Click:Connect(function(player)
times += 1
local car = game.ServerStorage.E200MMC:Clone()
car.Parent = workspace
car.Name = "car"..times
end)
A very simple solution though. Just add a number next to the name indicating which car is this. Simply said, adds one to a certain value every time a car is spawned and puts the value next to the name. This should work though I’m not sure if this is what you are looking for.
if you want the number to sound a bit more epic and random you can just put the times variable like so:
times += math.random(1,99)
It will be different everytime and wont be consecutive hopefully
Instead of making it a click detector, you can just make a part that spawns a vehicle when it’s touched then add hit.Parent in the name of the cloned vehicle.
local deb = false
game.Workspace.Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not deb then
deb = true
local car = game.ServerStorage.E200MMC:Clone()
car.Parent = workspace
car.Name = "car"..hit.Parent.Name
wait(2)
deb = false
end
end)
MouseButton1Click Function has no arguments.
Put the car’s model in ReplicatedStorage and
try this :
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local car = game.ReplicatedStorage.E200MMC:Clone()
car.Parent = workspace
car.Name = car.Name.." "..player.Name
end)
Additional notes: If this is a ServerScript, this will work (although not ideal). Otherwise, it’ll only spawn a car in on your screen and you’ll need to use RemoteEvents to spawn in the car for everyone to see.
I just read it again, it’s referencing ServerStorage which isn’t replicated in the first place to the client and on top of that, if that works somehow it will work but only for the client. OP is likely using a server script for this right now, but I’m not 100% sure.
yeah right, he needs to put the car’s model in like ReplicatedStorage for it to work (LocalScript), but if he wants it serversided he can keep it in ServerStorage and he just needs to fire a remotevent as you said.