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

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

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)

1 comment

0

You defined Clicker wrong it is a part not a ClickDetector.

3 answers

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

function onClicked()

end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 comment

0

can you edit in new post? to in my script beacuse im not understand where to put it..

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)

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