Im new to raycasting and Im attempting to summon a brick in the same direction of the player lookVector, and also I want to set an 25 stud offset on the z axis.
Line 15 and 16 are the lines where I tried to accomplish this.
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage.Remotes:WaitForChild("RemoteEvent")
remote.OnServerEvent:Connect(function(player)
local myplayer = player.character.HumanoidRootPart
local otherplayer = player.character.Head
local ray = Ray.new(myplayer.CFrame.p, (otherplayer.CFrame.LookVector).unit * 50)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, false)
local beam = Instance.new("Part")
beam.Transparency = 0
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
beam.Parent = workspace
beam.Size = Vector3.new(10, 10, 50)
beam.Position = (ray.Origin + Vector3(0,0,25))
beam.Orientation = (ray.Direction)
game:GetService("Debris"):AddItem(beam, .3)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(30)
end
end
end)
