I was trying to make a script, what makes a part called "beam" to appear, if the turrets "range2" part is touched, having one side at the turret, and second side at another part called "regular". I think everything is good to go, but the function wont run when the turrets "Range2" part is touched.
script.Parent.Range2.Touched:connect(function(enemy) print("touched") if enemy.Parent.Name == "Enemies" then print("rekt") local mag = (script.Parent.BeamS.Position - enemy.Position).magnitude local beam = Instance.new("Part") beam.BrickColor = BrickColor.new("Lily white") beam.Material = "Neon" beam.Transparency = 0.25 beam.Anchored = true beam.CanCollide = true beam.Size = Vector3.new(0.3,0.3,mag) beam.CFrame = CFrame.new(script.Parent.BeamS.Position, enemy.Position)*CFrame.new(0,0,-mag/2) beam.Parent = game.Workspace.CurrentCamera end end)
(This is the whole script)
And the OutPut doesn't print neither "rekt" or "touched".
Credit to OldPalHappy for pointing it out that local scripts can't run on the workspace.
Either Range2 hasn't loaded yet, or it doesn't exist. I'd recommend doing:
script.Parent:WaitForChild("Range2").Touched:connect(function(enemy) end)
Also, is the script disabled?
And you are trying to access the current camera. If this is a normal script, this will not work. And using a local script to do everything here wouldn't let this code run. I'd recommend using remote events to communicate between a script, which makes the parts, and the local script, which fiddles around the player's camera.