Im wanna make a npc spawner with button and this is the script and dont works why?
local Clicker = script.Parent --ClickDetector local Object = game.ReplicatedStorage:WaitForChild("Put") --Put is my object in replicatedstorage local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") --Object Spawner Clicker.onClicked:Connect(function() local CloneObject = Object:Clone() CloneObject.Parent = game.Workspace CloneObject.Position = Vector3.new(ObjectSpawn.Position) end)
PLEASE MAKE SURE TO ACCEPT THIS AS AN ANSWER IF IT SOLVED YOUR PROBLEM.
onClicked is not a valid event (I wish it was) MouseClick is the proper event. Also models don't have positions so you have to use the :MoveTo method. Vector3.new is not required here since Position is a Vector3 type.
local Clicker = script.Parent --ClickDetector local Object = game.ReplicatedStorage:WaitForChild("Put") --Put is my object in replicatedstorage local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") --Object Spawner Clicker.MouseClick:Connect(function() local CloneObject = Object:Clone() CloneObject.Parent = game.Workspace CloneObject:MoveTo(ObjectSpawn.Position) end)
Don't put that Vector3.new(ObjectSpawn.Position)
, the new
function can't take a Vector3 as an argument.
Plus, it looks like your NPC is a model. You can't set the position of a model, use :MoveTo()
instead.
local Clicker = script.Parent --ClickDetector local Object = game.ReplicatedStorage.Put --Put is my object in replicatedstorage local ObjectSpawn = game.Workspace.ObjectSpawn --Object Spawner Clicker.MouseClick:Connect(function() local CloneObject = Object:Clone() CloneObject.Parent = game.Workspace CloneObject:MoveTo(ObjectSpawn.Position) end)
Thus, removed the :WaitForChild()s, they're useless and may even cause the script to break if it yields too much, if the objects isn't created at that time.
EDIT: Also, the .OnClicked event does not exist, try using MouseClick instead.
This is till nothing, if there was putting a video in there i was clicking on the part and still nothing..