Script doesn't work when tool is clicked

Im trying to make a script where when you click on a part, it gives you a tool (already done that), but problem is, the tool simply wont activate. No errors even appear. What?

local DefaultBall = game.Workspace.DefaultBall
DefaultBall.glass.Case.ClickDetector.MouseClick:Connect(function(Player)
	local Character = Player.Character
	local Humanoid = Character.Humanoid
	-- Ball
	local Ball = script.Parent.Default_Ball
	local Tool = script.Parent
	local character = Tool.Parent
	-- Animation
	local Animation = Instance.new("Animation")
	Animation.AnimationId = "rbxassetid://13962251515"
	-- Settings
	local debounce = false -- Cooldown
	Animation.Parent = Humanoid.Animator

	Tool.Activated:Connect(function(activated)
		local HitAnimPlay = Humanoid:LoadAnimation(Animation)
		if not debounce then
			debounce = true
			HitAnimPlay:Play()
			wait(1.5)
			debounce = false
		end
	end)

	Ball.Touched:Connect(function(hit)
		local enemyplayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if not debounce then
			if enemyplayer then
				enemyplayer.Character.Humanoid.Health = - 10
				debounce = true
				wait(1.5)
				debounce = false
			end
		end
	end)
end)
1 Like

So when you click with the tool equipped, it doesn’t do anything?

You might want to try placing some print() functions around your script to self-debug it.

No, nothing happens. There is supposed to have an animation play to indicate it activated.

What does this part of the Script do, could you explain it to me?

It simply sees the part to give the ball was clicked, because if I didn’t put it there it would think ServerStorage is the player

Can I see the hierarchy of the tools in your Explorer? I’m a bit confused by just looking at only your script.

as @Deb0rahAliWilliams suggested, can you place some print statements around? Which ones print and which ones don’t? Specifically, in the Tool.Activated location and inside the conditional.

Sure, here it is
image
I ssuppose this is what you meant

If the Script you placed in at the first post is the one under the tool, why not just disable the Script under the tool, and when the Player clicks on the Case, the Script would just modify the Script to make in enabled?

This would be something that should be on the giver.

-- Variables
local Tool = game.ServerStorage:WaitForChild("Deafult_Ball")
-- Connecting when the ClickDetector gets triggered
script.Parent.MouseClick:Connect(function(plr)
-- Cloning the tool itself
		local ToolClone = Tool:Clone()
		ToolClone.Parent = plr.Backpack

		ToolClone.Script.Enabled = true

	end
end)

If this script is added, this means you don’t need to add this line to the Script, which may help debug your animation not playing:

I will be going offline for the night, so I won’t be responding to any replies that are within ~9 hours from when this reply is written.

1 Like

Thank you so much. It works now!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.