I'm making a turret, and I have this script which is supposed to fire at players while they're in it's range. The part named range is the area which people are supposed to be shot if they're touching. The boolean value I have is suppose to do this: If it's true, the ray should keep casting. if it's false, it shouldn't cast. I'm later going to add a script that makes it false if it isn't touching. The issue is, right now it only casts the ray once.
script.Parent.Parent.Range.Touched:Connect(function(hit) repeat if script.Parent.Parent.Range.Touched then if hit.Parent:FindFirstChild("Humanoid") and script.Parent.Value.Value == false then script.Parent.Value.Value = true local char = hit.Parent local ray = Ray.new(script.Parent.CFrame.p, (char.HumanoidRootPart.CFrame.p-script.Parent.CFrame.p).unit*1000) local part, position = workspace:FindPartOnRay(ray, script.Parent, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Royal purple") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = .25 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (script.Parent.CFrame.p - position).magnitude beam.Size = Vector3.new(.3,.3,distance) beam.CFrame = CFrame.new(script.Parent.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) game:GetService("Debris"):AddItem(beam, .1) end end wait(1) until script.Parent.Value == false end)