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

Why the button npc spawner not works? anyone help!

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)

5 comments

0

error please

0

Actually nvm

0

The script posted assumes that there is an object name "Put" in replicated storage, are you sure it exists?

0

Or does it output any error or message to the console?

0

Can't solve ur problem if u dont give an error

3 answers

✓ Accepted answer

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)

3 comments

0

What about the Vector3.new()? You didn't explain about it.

0

Correct.

0

still nothing but accepted for you

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.

7 comments

0

You forgot to look at the rest of the script and syntax error at line 8.

0

Looks like your using the word void improperly. A void function is a function that returns nothing.

0

Thanks, dumb mistakes.

0

MouseClick is not a valid member of Part

0

Use a ClcikDetector.

0

I do

0

No you're not. A ClickDetector isn't a part.

This is till nothing, if there was putting a video in there i was clicking on the part and still nothing..

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