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

How to create a button to spawn an object?

Hello

I want to create a button that when you press it an object will be spawned. I currently have no idea how to do this. cuase I'm new to scripting. Thats also why i dont have codes orso. Thanks if you know

Kees

1 answer

✓ Accepted answer

I will be helping you then, this would be like a tutorial but I do suggest you read some roblox wiki or other questions and answers before asking.

These are 2 way's to do this but I will show you the simple way;

Follow these steps;

  1. Insert a Part
  2. Make sure the part settings/properties are; Anchored = true, CanCollide = true
  3. Insert a ClickDetector into the part
  4. Insert a normal script into the ClickDetector
  5. Make the model/object you want to spawn
  6. Make sure the model and object is named and place it in the ReplicatedStorage
  7. Insert another part, make sure it has the same settings as the first part and name the part "ObjectSpawn"
  8. Place ObjectSpawn where you want the Object to spawn
  1. Place this code inside the script in ClickDetector;
local Clicker = script.Parent --ClickDetector
local Object = game.ReplicatedStorage:WaitForChild("ObjectName") --Put your object name here
local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") --Object Spawner

Clicker.onClicked:Connect(function() --Fires on Click
	local CloneObject = Object:Clone() --Clones the Object
	CloneObject.Parent = game.Workspace -- Send's it to Workspace
	CloneObject.CFrame.p --Change this to Position IF the script doesn't work = ObjectSpawn.CFrame.p
end)

This should spawn what you want spawned, if it doesn't work then change the last line to CloneObject.Position = Vector3.new(ObjectSpawn.Position)

If this helped then please Accept Answer

3 comments

0

Thanks

0

Np

0

Hi, I tried the script but it didn't work, is it because its outdated?

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