So, the script is supposed to shoot out a ball that does 10 damage, grows, etc. IT works just fine. That is until you unequip the tool and requip it. The output says "The Mouse Is No Longer Active", I can't wrap my head around how to fix this other than making the script reset all variables after it is unequipped.
local tool = script.Parent
tool.Equipped:connect(function(mouse)
local player = game.Players.LocalPlayer
oh = player.Character.Torso.Position
game:GetService("UserInputService").InputBegan:connect(function(inputObject,
gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
local blhl = Instance.new("Part", workspace)
blhl.Name = "blhl"
blhl.CFrame = CFrame.new(oh)
blhl.Shape = 0
blhl.BrickColor = BrickColor.new(1003)
blhl.CanCollide = false
local bp = Instance.new("BodyPosition", blhl)
bp.Position = Vector3.new(mouse.Hit.x,mouse.Hit.y,mouse.Hit.z)
bp.MaxForce = Vector3.new(10000, 10000, 10000)
bp.D = 30000
bp.P = 100000
local function ontouch(hit)
if workspace:findFirstChild("blhl") then
if hit.Parent:findFirstChild 'Humanoid' then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
blhl:Destroy()
end
end
end
blhl.Touched:connect(ontouch)
for i = .5, 5, .1 do
local h = blhl.CFrame
blhl.Size = Vector3.new(i,i,i)
blhl.CFrame = (h)
wait()
end
for i = 5, 10, .1 do
local h = blhl.CFrame
blhl.Size = Vector3.new(i,i,i)
blhl.CFrame = (h)
wait()
end
for i = 1, 0, .1 do
blhl.Transparency = i
wait()
blhl:Destroy()
end
while oh ~= player.Character.Torso.Position do
oh = player.Character.Torso.Position
end
end
end)
end)

2 comments
Thanks! This will also help me in the long run.
No problem :)