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)
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