local LaserPart = Instance.new("Part")
LaserPart.Color = Color3.fromRGB(255, 0, 0)
LaserPart.Anchored = true
LaserPart.CanCollide = false
LaserPart.Parent = workspace
local RayCastParameters = RaycastParams.new()
RayCastParameters.FilterDescendantsInstances = game.Workspace.HappyHome.Home.EyeOfSauron.Eye.Parent:GetChildren()
RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist
local function castRay(rTarget)
--print("Target in castRay is set to"..rTarget)
local laser_Thickness = .5
local rayOriginPart = Eye
local rayTargetPart = rTarget
local origin = rayOriginPart.CFrame.Position
local rayTarget = rayTargetPart.HumanoidRootPart.CFrame.Position
local direction = (rayTarget - origin)
local results = workspace:Raycast(origin, direction, RayCastParameters)
if not results then
results = {Position = rayTarget}
end
local distance = (results.Position - origin).Magnitude
LaserPart.Size = Vector3.new(laser_Thickness,laser_Thickness,distance)
LaserPart.CFrame = CFrame.new(origin, rayTarget - rTarget.Humanoid.MoveDirection * 2) * CFrame.new(0,0, -distance / 2)
--game.ReplicatedStorage.EyeEvent:FireAllClients(origin, rayTarget, distance, LaserPart)
end
local target
EyeEventRemote.OnClientEvent:Connect(function(Target)
target = Target
end)
RunService.RenderStepped:Connect(function()
if not target then return end
castRay(target)
end)
What is “Eye”? Is it a part attached to the player’s head? Can you send a gyazo of the laser in use with the player model?
Also,
Every time this remote event gets fired, a new .RenderStepped event gets connected. If you :FireClient the same player 10 times, there will be 10 RenderStepped events firing every frame doing the same time.
I would recommend to change it to:
EyeEventRemote.OnClientEvent:Connect(function(Target)
target = Target
end)
RunService.RenderStepped:Connect(function()
if not target then return end
castRay(target)
end)
Other than that, we don’t know how you’re currently setting up your model, so we can’t be sure of the issue.
The difference is very minuscule which suggests that it may just be some floating point precision error. I would suggest rounding the position to, say, the nearest hundredth or something.
Beams will generate a more fluent laser effect than baseparts, and if you wish to use .touched as hitbox detection then set the part’s transparency to 1.
Um well you i see,why dont you raycast from both the client as visual and from the aerver as the real lazer,this would eliminate replication lag and also be exploiter safe