Spawning an NPC using a Tool

I am trying to script a tool so it is able to spawn in an NPC I made.
When the tool is equipped and the player clicks their mouse the NPC will spawn in front of the player.
I have been having some trouble doing so though.
Can anyone help me with this?

1 Like

What thing that you have try before you open this topic?

Please describe what’s not working, and try to provide some code samples so we can better assist you.

Yes, we can help you, thats what we are here for, however you’ll need to provide some information for us to work with.

1 Like

So basically I have a model called ‘Player’ inside ReplicatedStorage that I want to be cloned into the workspace when a player has a certain tool equipped and the mouse being clicked.

Can you show the script that you have problem with?

2 Likes

This is the script I currently have for it which does not appear to be working as I thought it would:

local Tool = script.Parent;
local h = Tool.Parent:FindFirstChild(“Humanoid”)

script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function(player)
local d=game.ReplicatedFirst.Player:Clone()
d.Parent=workspace
d:MoveTo(game:GetService’Players’[player].Character:FindFirstChild’HumanoidRootPart’.Position)
end)
end)

Is that a LocalScript or a Script?

why don’t use Activated? it would be easier

It’s just a plain Script, not a local.

1 Like

I don’t fully understand how to use Activated.

1 Like

What exactly isn’t working?

(30 chars)

1 Like

Learn more about Tool.Activated

2 Likes

Well when I click, nothing seems to happen, it doesn’t do exactly as I thought it would.

1 Like

I’ll try working with this soon.

1 Like

Good luck with your game :))))

1 Like

Thank you for the help.
…

1 Like

As @GalaxySmediaCaster suggested, try using .Activated instead.

3 Likes

I’ve changed to Activate and this is what I have got now, but still does not work, I don’t see what I am doing wrong:

local tool = Instance.new(“Tool”)
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack

function onActivation(player)
local d=game.ReplicatedFirst.Zombie:Clone()
d.Parent=workspace
d:MoveTo(game:GetService’Players’[player].Character:FindFirstChild’HumanoidRootPart’.Position)
end

tool.Activated:Connect(onActivation)

1 Like

I’ve changed to Activate and this is what I have got now, but still does not work, I don’t see what I am doing wrong:

local tool = Instance.new(“Tool”)
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack

function onActivation(player)
local d=game.ReplicatedFirst.Zombie:Clone()
d.Parent=workspace
d:MoveTo(game:GetService’Players’[player].Character:FindFirstChild’HumanoidRootPart’.Position)
end

tool.Activated:Connect(onActivation)

1 Like
tool.Parent = game.Players.LocalPlayer.Backpack

This line will only work in a LocalScript