TestService: Exception thrown in your RayHit event handler: Argument 1 missing or nil
That’s the error I’m getting while firing my remote event which is an raycast event.
Here’s the more important part of the code:
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater = true
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate
local function onEquipped()
castParams.FilterDescendantsInstances = {viewmodel, bulletsFolder, character}
end
local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0, 0, -(length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
local function onRayHit(cast, result, velocity, bullet)
local hit = result.Instance
local character = hit:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") and playersmode then
local player3 = game.Players:GetPlayerFromCharacter(character)
if player3 then
if player3.TeamColor ~= player.TeamColor then
character.Humanoid:TakeDamage(damage)
end
else
-- do nothing
end
end
if character and character:FindFirstChild("Humanoid") and not playersmode then
character.Humanoid:TakeDamage(damage)
end
game:GetService("Debris"):AddItem(bullet, 1.2)
end
local function fire(player3, mousePosition)
local origin = firePoint
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 1000, castBehavior)
end
Anyone got a solution?