I barely know what this means, I know its a problem with tool.Activated:Connect(toolActivated) but I'm not sure how to fix it. I know I need to change "toolActivated" to something but I'm not sure what. Does anyone have an idea of what I change it to? The main issue is that this script sometimes works but half the time it says nil value and it doesn't work.
local sound = script.Parent.Handle:WaitForChild("Sound") local beam = script.Parent.Handle.Attachment:WaitForChild("Beam") local tool = script.Parent local player = tool.Parent.Parent local chargesound = script.Parent.Handle:WaitForChild("ChargeSound") local debounce = false repeat wait(1) until player.Character local character = player.Character local humanoid = character:WaitForChild("Humanoid") -- first animation local animation = Instance.new("Animation") animation.Name = "Idle" animation.Parent = script.Parent animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "5128762272" local animtrack = humanoid:LoadAnimation(animation) -- second animation local animation2 = Instance.new("Animation") animation2.Name = "Charge" animation2.Parent = script.Parent animation2.AnimationId = "http://www.roblox.com/asset/?id=" .. "5653045213" local animtrack2 = humanoid:LoadAnimation(animation2) -- action script.Parent.Equipped:connect(function() animtrack2:Play() sound:Stop() beam.Enabled = false chargesound:Play() if not debounce then function toolActivated() chargesound:Stop() animtrack2:Stop() animtrack:Play() wait(0.2) sound:Play() beam.Enabled = true wait(2) local debounce = true end end end) script.Parent.Unequipped:connect(function() animtrack:Stop() sound:Stop() animtrack2:Stop() chargesound:Stop() wait(.1) sound:Stop() local debounce = false end) tool.Activated:Connect(toolActivated)
toolActivated is in another event, meaning that it doesn't exist for things outside of that event, try putting the toolActivated event outside of the event, also using :Stop() on an animation when it is not already playing does not result in an error if that's why it is not outside of the event.