- What do you want to achieve?
So I’ve been perfecting a fps system with a few guns in a test game to transfer the code and assets over to the offical game I’m developing.
Transferred over everything but for some reason the raycast system is failing to work with one of my guns.
- What is the issue?
The gun worked perfectly fine perviously in the test game (I did rebuild the viewmodel but with only a few adjustments) However when firing this gun spacifically, the Raycast Instance comes back as BasePlate not matter what direction I fire it.
Here are some screenshots of my outliner and my fire function for the gun. I’ll Put a copy of my raycast code as well:
local GunEvent = RS.RemoteEvents:FindFirstChild("GunEvent")
local remoteEvent = RS.RemoteEvents:FindFirstChild("ShotEvents")
function fireBullet(Start: Vector3, End: Vector3, Orientation: Vector3)
findBullet()
Bullet.Position = Start
Bullet.Orientation = Orientation
local goal = {}
goal.Position = End
local tweenInfo = TweenInfo.new(speed, Enum.EasingStyle.Linear)
local tween = TweenService:Create(Bullet, tweenInfo, goal)
RunService.Heartbeat:Wait()
tween:Play()
end
GunEvent.OnServerEvent:Connect(function(player, item)
for i, v in pairs(game.ReplicatedStorage.Guns.Modules:GetChildren()) do
if v.Name == item then
Module = require(v)
print("Module is loaded")
Min_Spread = Module.Min_Spread
Max_Spread = Module.Max_Spread
dropOff = Module.DropOff
SpBullet = Module.IsSpecial
crit = Module.Crit
Chance = Module.Chance
MinDmg = Module.MinDmg
MaxDmg = Module.MaxDmg
end
end
end)
remoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
local startPoint = nil
local endPoint = nil
local Heading = nil
local direction = (mosPos - gunPos).Unit
local directionCF = CFrame.new(Vector3.new(), direction)
local newDirection = (directionCF * CFrame.fromOrientation(0, 0, RNG:NextNumber(0, TAU)) * CFrame.fromOrientation(math.rad(RNG:NextNumber(Min_Spread, Max_Spread)), 0, 0)).LookVector
RayCastParams.FilterDescendantsInstances = {player}
RayCastParams.FilterType = Enum.RaycastFilterType.Exclude
RayCastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(gunPos, newDirection * dropOff, RayCastParams)
if raycastResult then
if raycastResult.Distance <= dropOff then
startPoint = gunPos
endPoint = raycastResult.Position
Heading = gunOr
else
startPoint = gunPos
endPoint = gunPos + (newDirection * dropOff)
Heading = gunOr
end
else
startPoint = gunPos
endPoint = gunPos + (newDirection * dropOff)
Heading = gunOr
end
print(raycastResult.Instance)
fireBullet(startPoint, endPoint, Heading)
wait(speed)
CreateHole(raycastResult)
- What solutions have you tried so far?
I’ve tried figuring out what is the root cause but I can only think that is something in the gun or fire function I hve in the screenshot I sent above as all of my other guns work with this system.
If anyone can see any anomalies anywhere your help would be much apriciated