Basically I need help stopping a function that won’t stop running. Once I fire this function it wont stop running, it doesn’t end whatsoever. I put checks in place and it just doesn’t stop. I also tried using return and break, but I am not quite familiar with them.
The script is just a simple raycast script that makes a part that stretches from the players head to their mouse.
Here is the script:
function laser(no)
if no == false then
if player.Character.Humanoid.Health > 0 then
local mouseray = cam:ViewportPointToRay(mouse.X, mouse.Y)
local raycastresult = workspace:Raycast(mouseray.Origin, mouseray.Direction * 1000, rayparams)
local part = Instance.new("Part")
part.Anchored = true
if raycastresult then
print(raycastresult)
part.Parent = workspace
part.Position = player.Character.Head.Position
part.CanCollide = false
part.CFrame = CFrame.lookAt(part.Position, raycastresult.Position)
local mag = (raycastresult.Position - player.Character.Head.Position).Magnitude
part.Size = Vector3.new(1,1,mag)
part.CFrame = part.CFrame * CFrame.new(0,0,mag/-2)
local explosion = Instance.new("Explosion")
explosion.Parent = workspace
explosion.Position = raycastresult.Position
end
end
end
end
uis.InputBegan:Connect(function(input)
local fired = false
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if fired == false then
laser(fired)
print("hi")
fired = true
wait(3)
print("hi2")
fired = false
end
end
end)