Whenever I fire out of the 300 stud Raycast radius the whole fire script breaks and I can’t figure out why. I am clicking after the beam stops showing but it is not working. I have tried to look up returning if the part is not found but it does nothing.
Edit: I just realised that I was using a different script from something else still doesn’t work.
--Variables
local Wand = script.Parent
local Tip = script.Parent.Handle.End
local mouse = plr:GetMouse()
local Firing = false
local player = game:GetService("Players").LocalPlayer
--color of lightning
local cole = plr.Temp.cole.Value
--Equiped Or Not
Wand.Equipped:Connect(function()
equipped = true
end)
Wand.Unequipped:Connect(function()
equipped = false
end)
--Main
mouse.Button1Down:Connect(function()
if equipped and not Firing then
Firing = true
print("Clicked")
local ray = Ray.new(Wand.Handle.End.CFrame.p, (mouse.Hit.p - Wand.Handle.End.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local cole = player.Temp.cole.Value
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new(cole)
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (Wand.Handle.End.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(Wand.Handle.End.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
(Something Else That Works)
end
wait(1)
Firing = false
end
end
end)
[Solved]
Thanks for the quick responses I put the Firing = false in the wrong place.