-- Local script for firing player's mouse
local LAZAR = script.Parent
local Fire_LAZAR_Remote = script:WaitForChild("Fire_LAZAR")
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local debounce = false
LAZAR.Activated:Connect(function()
if debounce == true then return end
debounce = true
Fire_LAZAR_Remote:FireServer(Mouse)
task.wait(10)
debounce = false
end)
-- Server script for creating the lazar beam
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Fire_LAZAR_Remote = script.Parent
local LAZAR = Fire_LAZAR_Remote.Parent.Parent
local Handle = LAZAR:WaitForChild("Handle")
local Laser_Charge_Up = Handle:WaitForChild("Laser_Charge_Up")
local Laser_Fire = Handle:WaitForChild("Laser_Fire")
local Starting_Point = Handle:WaitForChild("Starting_Position")
local MAX_RANGE = 300
local function Toggle_Scripts(character, Toggle_Value)
for i, v in character:GetDescendants() do
if not v:IsA("LocalScript") or not v:IsA("Script") or v == script then continue end
v.Enabled = Toggle_Value
end
end
local function Fire_Laser_Sound(HRP)
local Laser_Fire_Clone = Laser_Fire:Clone()
Laser_Fire_Clone.Parent = HRP
Laser_Fire_Clone:Play()
end
local function Laser_Warning(character, Humanoid)
Toggle_Scripts(character, false)
local Highlight = Instance.new("Highlight")
Highlight.Parent = character
Humanoid.WalkSpeed = 0
task.wait(Laser_Charge_Up.TimeLength)
Toggle_Scripts(character, true)
Highlight:Destroy()
end
Fire_LAZAR_Remote.OnServerEvent:Connect(function(player, playerMouse)
local character = player.Character
local Humanoid = character:WaitForChild("Humanoid")
local HRP = character:WaitForChild("HumanoidRootPart")
local LAZAR_BEAM = Instance.new("Part")
LAZAR_BEAM.Anchored = true
LAZAR_BEAM.Color = Color3.fromRGB(0, 255, 255)
LAZAR_BEAM.Material = Enum.Material.Neon
LAZAR_BEAM.CanCollide = false
LAZAR_BEAM.Size = Vector3.new(1, 1, 1)
LAZAR_BEAM.Position = Starting_Point.WorldCFrame.Position + Vector3.new(0, 0, 6)
local Laser_Charge_Up_Clone = Laser_Charge_Up:Clone()
Laser_Charge_Up_Clone.Parent = HRP
Laser_Charge_Up_Clone:Play()
local Charge_LAZAR_Beam = TweenService:Create(LAZAR_BEAM, TweenInfo.new(Laser_Charge_Up_Clone.TimeLength, Enum.EasingStyle.Linear), {Size = Vector3.new(5, 5, 5)})
Charge_LAZAR_Beam:Play()
task.spawn(Laser_Warning, character, Humanoid)
Charge_LAZAR_Beam.Completed:Wait()
local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterType = Enum.RaycastFilterType.Exclude
RaycastParameters.FilterDescendantsInstances = {LAZAR, character, LAZAR_BEAM}
RaycastParameters.IgnoreWater = true
local Direction = (playerMouse.Hit.Position - Starting_Point.WorldCFrame.Position)
local RayResults = game.Workspace:Raycast(Starting_Point.WorldCFrame.Position, Direction, RaycastParameters)
task.spawn(Fire_Laser_Sound, HRP)
LAZAR_BEAM.CFrame = CFrame.lookAt(Starting_Point.WorldCFrame.Position, playerMouse.Hit.Position)
if not RayResults then
LAZAR_BEAM.Size = Vector3.new(5, 5, MAX_RANGE)
else
LAZAR_BEAM.Size = Vector3.new(5, 5, RayResults.Distance)
end
local Disappear_Tween = TweenService:Create(LAZAR_BEAM, TweenInfo.new(Laser_Fire.TimeLength, Enum.EasingStyle.Linear), {Transparency = 1})
Disappear_Tween:Play()
Disappear_Tween.Completed:Wait()
LAZAR_BEAM:Destroy()
end)
I’m trying to create a laser beam where it has to charge up and then fires a beam so I’m attempting to access the player’s mouse in case their mouse position has changed while charging up the beam but it errored at line 68.
local Direction = (playerMouse.Hit.Position - Starting_Point.WorldCFrame.Position)
I’m not sure how to fix this?