What this is supposed to do is whenever the player is near, it fires bullets at it. Here is the script:
local part = script.Parent local player = game.Players.LocalPlayer local damage = 10 local mouse = player:GetMouse() local range = 100 function Range () local mag = (part.CFrame.p - player.Character.Torso.CFrame.p).magnitude part.Parent.Rotation = player.Character.Torso.Position if mag >= range then local bullet = Instance.new("Part", game.Workspace) bullet.Name = "Bullet" bullet.Shape = "Ball" bullet.FormFactor = "Custom" bullet.Size = Vector3.new(0.2,0.2,0.2) bullet.TopSurface = "Smooth" bullet.BottomSurface = "Smooth" bullet.BrickColor = BrickColor.new("Medium stone grey") bullet.CanCollide = false bullet.CFrame = part.CFrame bullet.CFrame = CFrame.new(bullet.Position, player.Character.Torso.p) local v = Instance.new("BodyVelocity", bullet) v.Velocity = bullet.CFrame.lookVector * 90 v.MaxForce = Vector3.new(math.huge, math.huge, math.huge) end end Range()
Thank you LordDragon, I fixed it on my own though, here is my new problem: The problem is at Line 7, where the while loop is introduced.
local part = script.Parent local damage = 10 local range = 10 game.Players.PlayerAdded:connect(function(char) char.CharacterAdded:connect(function() while (char.Character.Torso.CFrame.p - part.CFrame.p).magnitude <= range do local bullet = Instance.new("Part", game.Workspace) bullet.Name = "Bullet" bullet.Shape = "Ball" bullet.FormFactor = "Custom" bullet.Size = Vector3.new(0.2,0.2,0.2) bullet.Transparency = 0 bullet.TopSurface = "Smooth" bullet.BottomSurface = "Smooth" bullet.BrickColor = BrickColor.new("Bright yellow") bullet.CanCollide = false bullet.CFrame = part.CFrame bullet.CFrame = CFrame.new(bullet.Position, char.Character.Torso.Position) local v = Instance.new("BodyVelocity", bullet) v.velocity = bullet.CFrame.lookVector * 90 v.maxForce = Vector3.new(math.huge, math.huge, math.huge) part.Fire:Play() local hum = char.Character:FindFirstChild("Humanoid") hum:TakeDamage(damage) game.Debris:AddItem(bullet, 2) wait(0.5) end end) end)