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

I want to make an NPC Spawner with button but not works why?

Asked by 6 years ago
Edited 6 years ago

I want to make an NPC Spawner with button. When we press the button then the npc spawns. Have a clickdetector in button but still nothing "MouseClick" is not a valid member of a part. This is an error what i get first in the output once. If i click i dont get more errors just don't spawn the NPC.

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)
0
You defined Clicker wrong it is a part not a ClickDetector. hellmatic 1523 — 6y

3 answers

Log in to vote
0
Answered by
PastDays 108
6 years ago
Edited 6 years ago

Try this, this is my template that has always worked for me.

function onClicked()

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
can you edit in new post? to in my script beacuse im not understand where to put it.. Minekaft153 -15 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Still not works, please anyone help. :(

Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago
local Object = game.ReplicatedStorage.Put --Put is my object in replicatedstorage
local ObjectSpawn = game.Workspace.ObjectSpawn --Object Spawner

function onClicked()
    local CloneObject = Object:Clone()
    CloneObject.Parent = game.Workspace
    CloneObject:MoveTo(ObjectSpawn.Position)
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Answer this question