I am trying to make a blood module, so that when I pass a position through it, it makes 1-3 blood parts that fly around.
When I pass a variable through to the module, it reads it as nil even though when I print it the line before it has the position value.
I tried setting the position as a variable the line before instead of passing it in straight away but it’s still nil
This is when I call it:
print(hit.CFrame)
local position = hit.Position
print(hit.Position)
BloodModule.SpawnRandomParts(position)
This is my module function:
function FlyingPartsModule:SpawnRandomParts(spawnPosition)
-- Generate 1 to 3 random parts
local partCount = math.random(1, 3)
print(spawnPosition)
for i = 1, partCount do
local part = bloodPart:Clone()
part.Position = spawnPosition
part.Parent = workspace.Effects
-- Adjusted velocity for slight upward angle and random horizontal variations
part.Velocity = Vector3.new(
math.random(-20, 20), -- Horizontal variation
math.random(40, 60), -- Upward force
math.random(-20, 20) -- Horizontal variation
)
part.Touched:Connect(function(hit)
if self.isValidHit(hit) then
self.OnPartTouchGround(part, hit)
end
end)
end
end
And this is what is outputted:
12:41:16.987 1270.04578, 663.439392, 11120.3291, 0.976294279, 1.06434126e-15, 0.216447413, -1.14764642e-15, 1, 2.59182447e-16, -0.216447413, -5.01443452e-16, 0.976294279 - Server - HitService:86
12:41:16.987 1270.0457763671875, 663.4393920898438, 11120.3291015625 - Server - HitService:88
12:41:16.987 nil - Server - BloodModule:20
12:41:16.987 Unable to assign property Position. Vector3 expected, got nil - Server - BloodModule:24