I am having an issue with my gun system, I am raycasting on the client and then passing the raycast information to the server and it works, however only half of the time.
I tried debugging it by printing and each time the instance of the raycast is a humanoid, on the server it is nil and it causes an error.
The first print is from the client (Humanoid) and the second one is from the server (nil)
CLIENT CODE:
local direction = applyPhysics(GetMousePosition(location.x,location.y))
local rayFilter = RaycastParams.new()
rayFilter.FilterDescendantsInstances = bl
rayFilter.FilterType = Enum.RaycastFilterType.Blacklist
local ray = workspace:Raycast(script.Parent.Nodes.FirePart.Position, direction, rayFilter)
if ray then
print(ray.Instance.Name)
game.ReplicatedStorage.Apollo.Damage:FireServer(ray.Instance, script.Parent, ray.Position, ray.Normal)
produceBeam(script.Parent.Nodes.FirePart, ray.Position)
if ray.Instance.Parent:FindFirstChild("Humanoid") or ray.Instance.Parent.Parent:FindFirstChild("Humanoid") then
blood(ray.Position)
end
else
produceBeam(script.Parent.Nodes.FirePart, direction)
end
SERVER CODE:
game.ReplicatedStorage.Apollo.Damage.OnServerEvent:Connect(function(plr, ray, tool, pos, normal)
print(ray)
if ray.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Apollo.Blood:FireAllClients(plr, pos)
local char = ray.Parent
local conf = require(tool.Settings)
char.Humanoid:TakeDamage(conf.damage)
end
end)
-- NOTE: RAY IS THE RAYCAST INSTANCE