Obviously, I can't access the camera inside the serverScript…. does anyone know a way to pass the information on through a RemoteEvent.. I am very new to these remote events. Basically, I am trying to make this code work inside a serverScript:
local ignoreList = {} table.insert(ignoreList, player.Character) local Debris = game:GetService("Debris") local ray = camera:ScreenPointToRay(mouse.X, mouse.y, 1) local startPoint = Instance.new("Part", workspace) startPoint.Size = Vector3.new(1,1,1) startPoint.CFrame = CFrame.new(ray.Origin, ray.Origin + ray.Direction) startPoint.Anchored = true startPoint.CanCollide = false startPoint.Transparency = 1 startPoint.Name = ("bulletPart") Debris:AddItem(startPoint, .05) local endPointRay = camera:ScreenPointToRay(mouse.X, mouse.y, 300) local endPoint = Instance.new("Part", workspace) endPoint.Size = Vector3.new(1,1,1) endPoint.CFrame = CFrame.new(endPointRay.Origin, endPointRay.Origin + endPointRay.Direction) endPoint.Anchored = true endPoint.CanCollide = false endPoint.Transparency = 1 endPoint.Name = ("bulletPart") local startBeamRay = Ray.new(startPoint.CFrame.p, (endPoint.CFrame.p - startPoint.CFrame.p).unit * 50) local hit, pos = workspace:FindPartOnRayWithIgnoreList(startBeamRay, ignoreList, false, true) local dist = (startPoint.Position - pos).magnitude local beam = Instance.new("Part", workspace) beam.Anchored = true beam.CanCollide = false beam.Transparency = 1 beam.BrickColor = BrickColor.new("Cool yellow") beam.Size = Vector3.new(.2,.2,dist) beam.CFrame = CFrame.new(startPoint.CFrame.p, pos) * CFrame.new(0,0, -dist / 2) beam.Name = ("bulletPart") local oldPos = pos if hit then local humanoid = hit.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = hit.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then humanoid:TakeDamage(30) end end Debris:AddItem(beam, .08) if hit == nil then repeat local newBeamRay = Ray.new(oldPos, (endPoint.CFrame.p - oldPos).unit * 20) local hit, pos = workspace:FindPartOnRayWithIgnoreList(newBeamRay, ignoreList, false, true) local dist = (oldPos - pos).magnitude local Newbeam = Instance.new("Part", workspace) Newbeam.Anchored = true Newbeam.CanCollide = false Newbeam.Transparency = .25 Newbeam.BrickColor = BrickColor.new("Cool yellow") Newbeam.Size = Vector3.new(.2,.2,dist) Newbeam.CFrame = CFrame.new(oldPos, pos) * CFrame.new(0,0, -dist / 2) Newbeam.Name = ("bulletPart") oldPos = pos if hit then local humanoid = hit.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = hit.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then humanoid:TakeDamage(30) end end Debris:AddItem(Newbeam, .02) wait(.03) until hit ~= nil Debris:AddItem(endPoint, .05) end
I need that to happen inside a Server script but am not sure how to make that happen... Im sure there are errors in my code too so feel free to say if there is a place I can improve.