I am getting lost here. I am trying to rework my system so it is not as laggy, right now, all I am doing is trying to make the rayCast on the client, but I seem to keep getting errors with the Target, would love some help, I can show you my current error, but every time I fix one thing it seems to break another.
Error 1: Attempt to connect failed: Passed value is not a function, Error 2: attempt to call a nil value
Most of my client sided code:
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) * CFrame.new(0,0, -distance / 2)
--game.ReplicatedStorage.EyeEvent:FireAllClients(origin, rayTarget, distance, LaserPart)
end
local target
EyeEventRemote.OnClientEvent:Connect(function(Target)
target = Target
RunService.RenderStepped:Connect(castRay(target))
end)
Main part of server script:
function startGame()
local Target = FindNearest()
local TargetPrimaryPart = Target or Target.PrimaryPart
EyeEventRemote:FireAllClients(Target)
local Detector = Instance.new("Part")
Detector.Anchored = true
Detector.CanCollide = false
Detector.Transparency = 0.5
Detector.Color = Color3.fromRGB(255, 0, 0)
Detector.Size = Vector3.new(1, 1, 1) * 4
end
I can provide more information if needed.