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

Is it possible to spawn an object/model with clickdetector?

I made a button with a clickdetector and tried to make a script where one random model spawns into workspace out of many from ServerStorage. Unfortunately I am unable to complete this, and need help with this.

Here is the script I tried:

local Clicker = script.Parent --ClickDetector
local Object = game.ReplicatedStorage:WaitForChild("ObjectName") --Put your object name here
local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") --Object Spawner

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

3 comments

0

Please don't take this down

0

if you attempted a script, post it or nobody will help. and it sounds like you have tried a script

0

there u go robloxiandestroy

2 answers

✓ Accepted answer
local Clicker = script.Parent 
local Object = game.Lighting:WaitForChild("ObjectName") -- change "ObjectName" to the name of your part
ObjectSpawn = game.Workspace:FindFirstChild("ObjectSpawn")

Clicker.ClickDetector.MouseClick:Connect(function(player)
	Object:Clone().Parent = game.Workspace
end)

line 1

local Clicker = script.Parent --ClickDetector

line 5

ClickDetector.MouseClick:connect(function() --Fires on Click

if the script is in the ClickDetector, rename ClickDetector to Clicker or add Clicker.ClickDetector.

also, i tried this script and it wasn't changing the position to the spawn position for some reason. I haven't use Vector3 for a while, but it shouldn't be changed from what it was.

the cloned object was spawning at 0,0,0

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