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?
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.
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?
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.
I donât fully understand how to use Activated.
What exactly isnât working?
(30 chars)
Learn more about Tool.Activated
Well when I click, nothing seems to happen, it doesnât do exactly as I thought it would.
Iâll try working with this soon.
Good luck with your game :))))
Thank you for the help.
âŚ
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)
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)
tool.Parent = game.Players.LocalPlayer.Backpack
This line will only work in a LocalScript