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

Can you make a spawn button that can spawn cars ive inserted from the toolbox?

Can you make a spawn button that can spawn cars ive inserted from the toolbox? ive tried to to follow diffrent instruction on how to regen and how to spawn parts, but i have found nothing on inserted objects. is it even possible?

sorry, im very very new at scripting

1 comment

0

This is a request. requests are against scriptinghelpers rules. I will do it though

1 answer

Again, this website is not meant for requests.

Put this code inside a part, and put your model in ServerStorage.

local TIMEOUT = false --plz dont change this
local RECHARGE = 3 --Time it takes for the button to be used again
local CAR_NAME = "car" --Name of the car model goes here. (Put the model in serverStorage)
--Keep in mind that if your car is a model (any functional car most likely is) then you will need to set its PrimaryPart property.


script.Parent.Touched:Connect(function(t)
	if t.Parent:IsA("Model") then
		if t.Parent:FindFirstChildOfClass("Humanoid") then
			
			local p = game.ServerStorage:FindFirstChild(CAR_NAME)
			if p then
				if TIMEOUT == false then
					TIMEOUT = true
					
					local c = p:Clone()
					c.Parent = game.Workspace
					if c:IsA("Model") then
						c:SetPrimaryPartCFrame(CFrame.new(script.Parent.Position - script.Parent.CFrame.LookVector*-1)) --Put model behind the button
					else
						c.Position = script.Parent.Position - script.Parent.CFrame.LookVector*-7 -- Put part behind the button
					end
					local oldColor = script.Parent.Color
					script.Parent.Color = Color3.new(1,0,0) -- Turn red while it is not in use
					wait(RECHARGE)
					TIMEOUT = false
					script.Parent.Color = oldColor
				end
			end
			
		end
	end
end)

In the future, please do not post requests (asking people to write scripts or make models) and ask for help (e.g - how do i do this, what is wrong with this segment of code)

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