I think it is firing many times, before ending, the damage per second is being spammed so it happens instantly.
I am still new to bindable events so is it not ending or something?
I have a game mode that has a big laser, and it tracks the user just behind them until they stop, then it catches up, if it hits a part, it deletes it and flings parts around it, basically eye of sauron
Here is my code
local debounce = false
local running = false
local Target
BindableEvent.Event:Connect(function(isRunning, id)
print("called with", id)
if running and isRunning then return end
running = isRunning
while running do
local target = FindNearest(rayOriginPart.Position)
print("Is running")
if target then
Target = target.HumanoidRootPart
end
local origin = rayOriginPart.CFrame.Position
local rayTarget = target_previous:Lerp(Target.Position, laser_TrackingAccuracy)
local direction = (rayTarget - origin)
local results = workspace:Raycast(origin, direction * 100, raycastParameters)
if not results then
results = {Position = rayTarget}
else
if results.Instance.Parent:FindFirstChild("Humanoid") and not results.Instance:IsDescendantOf(workspace.HappyHome) and not results.Instance.Parent:IsA("Accessory") then
if debounce == false then
debounce = true
local targetChar = Instance.Parent
if targetChar then
takeDamage(targetChar.Humanoid)
else debounce = false
end
wait(2)
debounce = false
end
elseif results.Instance:IsDescendantOf(workspace.HappyHome) then
local NewDetector = Detector:Clone()
NewDetector.Parent = workspace
NewDetector.Position = results.Instance.Position
local PartsList = NewDetector:GetTouchingParts()
results.Instance:Destroy()
for _,Part in ipairs(PartsList) do
if Part:IsDescendantOf(workspace.HappyHome.Home.House) then
Part:BreakJoints()
Part:ApplyImpulse(math.random(1, 100), math.random(100, 500), math.random(1,100))
end
end
NewDetector:Destroy()
end
end
local distance = (results.Position - origin).Magnitude
local LaserPosition = laserPart.Position
LaserPart.Size = Vector3.new(laser_Thickness,laser_Thickness,distance)
laserPart.CFrame = CFrame.new(origin, results.Position) * CFrame.new(0,0, -distance/2)
target_previous = rayTarget
wait()
end
print("ending")
end)
