I’m making a gun system and I want to add bullet holes, the gun system that I’m using can be found here:
And I’m using this to help w/ the bullet holes.
The error I keep getting is “Position is not a valid member of Ray”. I dont know if this like a dummy question but I need help fixing it.
Here is the code for the raycast (I am not sure which one to choose)
local ray = Ray.new(from.Position, from.CFrame.lookVector*500);
local hit, pos, normal = game.Workspace:FindPartOnRayWithIgnoreList(ray, {self.humanoid.Parent, self.weapon});
local rayOrigin = part.Position
local rayDirection = part.CFrame.LookVector * 500
local raycast = workspace:Raycast(rayOrigin, rayDirection)
if raycast then
local position = raycast.Position
-- stuff
end
local r = RaycastParams.new()
r.FilterDescendantsInstances = {self.humanoid.Parent, self.weapon}
Local ray = workspace:Raycast(from.Position,from.CFrame.LookVector*500,r)
if ray then
print(ray.Position,ray.Normal)
end
--Module
function fps:fire()
if (self.isEquipped and self.isAlive) and enableGun == true then
local r = RaycastParams.new()
r.FilterDescendantsInstances = {self.humanoid.Parent, self.weapon}
local from = self.isAiming and self.weapon.Aim or self.weapon.Shoot;
local ray = workspace:Raycast(from.Position, from.CFrame.lookVector*500, r);
--local hit, pos, normal = workspace:FindPartOnRayWithIgnoreList(ray, {self.humanoid.Parent, self.weapon});
local hit, pos, normal = workspace:FindPartOnRayWithIgnoreList(ray, {self.humanoid.Parent, self.weapon})
local shotgun_ray
--for i = 1, pelletCount do --Create a loop that repeats itself based on the amount of pellets being shot
--local pelletSpread = Vector3.new(rng:NextNumber(-maximumOffset, maximumOffset), rng:NextNumber(-maximumOffset, maximumOffset), rng:NextNumber(-maximumOffset, maximumOffset)) --Create a Vector3 that consists of a randomization of all the axes.
--ray = Ray.new(from.Position, from.CFrame.lookVector+pelletSpread*500) --Create an equation of Mouse.Hit.LookVector + the pelletSpread.
--end
local enemyHum;
if (hit) then
local players = game.Players:GetPlayers();
for i = 1, #players do
if (players[i].Character and hit:IsDescendantOf(players[i].Character)) then
enemyHum = players[i].Character:FindFirstChild("Humanoid");
break;
end
end
if (enemyHum) then
enemyHum:TakeDamage(self.settings.damageFunc())
end
end
self.recoil.p = self.settings.recoilFunc();
remotes.fire:FireServer(self.Right, self.Left, enemyHum);
if ray.Instance then
remotes.raypos:FireServer(ray.Position, ray.Normal)
end
print(pos)
local serverWeapon = self.humanoid.Parent:FindFirstChild(self.weapon.Name)
local fireSound = serverWeapon.Handle:FindFirstChild("Fire");
if (fireSound) then
fireSound:Play();
end
end
end
Same error: Unable to cast RaycastResult to Ray and ContextActionService: Unexpected error while invoking callback: Unable to cast RaycastResult to Ray