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

My script to print something when activate a tool wont work. How do i fix this?

local SwingAnim = game.workspace.Animations.Swing
local Pluck = game.StarterPack.Pluck
function onTouched(Obj)
	local h = Obj.Parent:FindFirstChild("Humanoid")
	if h then
		h.Health = 0
	end
end

script.Parent.Touched:Connect(onTouched)

Pluck.Activated:Connect(function()
	print("Swing starts now")
end)

3 comments

0

Make sure that you have activated the tool while testing.

0

yes i have activated it

0

Make sure that the script is a local script

1 answer

So there are a few things wrong with this (what I assume to be) ServerScript. First, you're trying to reference the player's backpack with game.StarterPack. This is a problem because once your game runs everything in StarterPack is copied into the player's Backpack. So you won't really be making any changes to the current tool. To do this just put a LocalScript into the tool and write this:

local tool = script.Parent

tool.Equipped:Connect(function()
	tool.Activated:Connect(function()
		print("Swing starts now")
	end)
end)

1 comment

0

tool.Equipped and toolActivated are the same thing.

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