RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make it to shoot the lasers to the mouse position"
-- server script local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local leftEye = character.Head:WaitForChild("LeftEye") local rightEye = character.Head:WaitForChild("RightEye") local function fireLaser(eye, target) local ray = Ray.new(eye.Position, (target - eye.Position).Unit * 1000) local hit, pos = game.Workspace:FindPartOnRay(ray, character) local beam = Instance.new("Part") beam.Parent = game.Workspace beam.BrickColor = BrickColor.Red() beam.FormFactor = "Custom" beam.Material = "Neon" beam.Anchored = true beam.CanCollide = false beam.Size = Vector3.new(0.2, 0.2, (pos - eye.Position).Magnitude) beam.CFrame = CFrame.new(eye.Position, pos) * CFrame.new(0, 0, -beam.Size.Z / 2) if hit and hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(10) end game:GetService("Debris"):AddItem(beam, 0.1) end local function onInputBegan(input, gameProcessed) if input.KeyCode == Enum.KeyCode.E then while UserInputService:IsKeyDown(Enum.KeyCode.E) do local mousePosition = UserInputService:GetMouseLocation() local mouseTarget = workspace:CurrentCamera:ScreenPointToRay(mousePosition.X, mousePosition.Y).Direction * 1000 fireLaser(leftEye, mouseTarget) fireLaser(rightEye, mouseTarget) RunService.RenderStepped:Wait() end end end UserInputService.InputBegan:Connect(onInputBegan)