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

Why the button npc spawner not works? anyone help!

Asked by 5 years ago
Edited 5 years ago

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)
0
error please Griffi0n 315 — 5y
0
Actually nvm Griffi0n 315 — 5y
0
The script posted assumes that there is an object name "Put" in replicated storage, are you sure it exists? LollipopCraft 1 — 5y
0
Or does it output any error or message to the console? LollipopCraft 1 — 5y
0
Can't solve ur problem if u dont give an error Griffi0n 315 — 5y

3 answers

Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
What about the Vector3.new()? You didn't explain about it. Aimarekin 345 — 5y
0
Correct. Griffi0n 315 — 5y
0
still nothing but accepted for you Minekaft153 -15 — 5y
Ad
Log in to vote
0
Answered by
Aimarekin 345 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
You forgot to look at the rest of the script and syntax error at line 8. Griffi0n 315 — 5y
0
Looks like your using the word void improperly. A void function is a function that returns nothing. Griffi0n 315 — 5y
0
Thanks, dumb mistakes. Aimarekin 345 — 5y
0
MouseClick is not a valid member of Part Minekaft153 -15 — 5y
View all comments (3 more)
0
Use a ClcikDetector. Aimarekin 345 — 5y
0
I do Minekaft153 -15 — 5y
0
No you're not. A ClickDetector isn't a part. Aimarekin 345 — 5y
Log in to vote
0
Answered by 5 years ago

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

Answer this question