I get an error with this script, it works just fine in a localscript, but when i trigger it with a remote-event it errors on line 39. Does anyone know how to fix this issue?
script:
local EventQ = game:GetService("ReplicatedStorage").Remotes.EventQ game:GetService("Players").PlayerAdded:Connect(function(player) local cooldownQ = Instance.new("NumberValue") local healticks = 0 local Character = player.Character cooldownQ.Name = "cooldownQ" cooldownQ.Parent = player end) EventQ.OnServerEvent:Connect(function(player,cooldownQ) local humanoid = player.Character.Humanoid local Debris = game:GetService("Debris") local LaserGun = player.Character.BLaserGun local cooldownQ = 10 local mouse = player:GetMouse() local Character = player.Character if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping or humanoid:GetState() ~= Enum.HumanoidStateType.FallingDown then if os.time() - player.cooldownQ.Value > cooldownQ then player.cooldownQ.Value = os.time() local beamsource = game.ReplicatedStorage.LazerBeam.Tip local clonedbeamsource = beamsource:Clone() local varX = player.Character.Torso.Position.X local varY = player.Character.Torso.Position.Y local varZ = player.Character.Torso.Position.Z clonedbeamsource.Parent = game.Workspace clonedbeamsource.Position = Vector3.new(varX, varY +6, varZ) wait(2) local Tip = game.Workspace.Tip local Laser = Ray.new(Tip.CFrame.p, (mouse.Hit.p - Tip.CFrame.p).unit * 300) --error in line above local HitPart, HitPosition = game.Workspace:FindPartOnRay(Laser, Character, false, true) local dmgscript = game.ReplicatedStorage.LazerBeam.dmg local cloneddmgscript = dmgscript:Clone() local LaserBeam = Instance.new("Part", game.Workspace) LaserBeam.BrickColor = BrickColor.new("Bright red") LaserBeam.FormFactor = "Custom" LaserBeam.Material = "Neon" LaserBeam.Transparency = 0.25 LaserBeam.Anchored = true LaserBeam.CanCollide = false LaserBeam.Name = "LaserBullet" cloneddmgscript.Parent = game.Workspace.LaserBullet local LaserDistance = (Tip.CFrame.p - HitPosition).Magnitude LaserBeam.Size = Vector3.new(2, 2, LaserDistance) LaserBeam.CFrame = CFrame.new(Tip.CFrame.p, HitPosition) * CFrame.new(0, 0, -LaserDistance/2) Debris:AddItem(LaserBeam, 2) end end end )