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

How to create a button to spawn an object?

Asked by
kees31 13
7 years ago

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

Log in to vote
-1
Answered by 7 years ago

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

  9. 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

0
Thanks kees31 13 — 7y
0
Np BlackOrange3343 2676 — 7y
0
Hi, I tried the script but it didn't work, is it because its outdated? ProjectChampion1 0 — 2y
Ad

Answer this question