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

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

Asked by 5 years ago
Edited by theking48989987 5 years ago

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)

0
Please don't take this down User#30241 0 — 5y
0
if you attempted a script, post it or nobody will help. and it sounds like you have tried a script RobloxianDestory 262 — 5y
0
there u go robloxiandestroy User#30241 0 — 5y

2 answers

Log in to vote
0
Answered by
3wdo 198
5 years ago
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)
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question