I want bullets to spawn from the barrel of the Viewmodel gun, which is the visual model the player sees.
However, the bullets are currently spawning from the Tool’s Handle part, not the Viewmodel’s barrel.
I’ve searched through YouTube and the Developer Forum, but I haven’t found a solution to this problem yet.
In this image, red represents the Viewmodel (the gun the player sees), and blue represents the Tool (the actual functional part).
Currently, bullets spawn from the blue part, but I want them to spawn from the red part (the Viewmodel’s muzzle).
I also tried accessing the position of the Viewmodel’s muzzle part in a LocalScript.
It didn’t return nil, but it seems to be giving the wrong position.
I also tried getting the position of the Viewmodel’s muzzle part in a LocalScript, but it returned nil or didn’t work at all.
I looked through YouTube and the Developer Forum but couldn’t find a solution yet.
I tried accessing the position of the Viewmodel’s muzzle part in a LocalScript, it seems to be giving the wrong position
heres my small part of localscript and server script(yea i know those scripts are suck)
local script:
> RemoteFolder.FireGun:FireServer(Mouse.Hit.p, viewmodel.m4a1.Muzzle.MuzzleAttachment.WorldCFrame.Position)
> print(viewmodel.m4a1.Muzzle.MuzzleAttachment.WorldCFrame.Position)
server script:
FireGunEvent.OnServerEvent:Connect(function(player, mouseposition, m4origin)
if Guncool == false and Mag > 0 then
Mag -= 1
Guncool = true
params.FilterDescendantsInstances = {player.Character}
localplayer = player
Muzzle.Fire:Play()
local randomYaw = math.rad(math.random(-spreadAngle, spreadAngle))
local randomPitch = math.rad(math.random(-spreadAngle, spreadAngle))
local spreadCFrame = CFrame.Angles(randomPitch, randomYaw, 0)
local direction = (mouseposition - m4origin).Unit
local Origin = m4origin
print(m4origin)
print(direction)
local bulletclone = bullet:Clone()
bulletclone.Parent = workspace
VisualizePoint(m4origin, 100)
local caster = FastCastRedux.new()
local behaviour = caster.newBehavior()
behaviour.RaycastParams = params
local gravity = Vector3.new(0, -workspace.Gravity, 0)
behaviour.Acceleration = gravity
caster.LengthChanged:Connect(function(cast, lastpoint, dir, length)
local blength = bulletclone.Size.Z / 2
local offset = CFrame.new(0, 0, -(length - blength))
bulletclone.CFrame = CFrame.lookAt(lastpoint, lastpoint + dir):ToWorldSpace(offset)
end)
caster.RayHit:Connect(function(ray, result)
local hit = result.Instance
local hitPosition = result.Position
local hitNormal = result.Normal
local character = GetCharacterFromHit(hit)
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
print(hit, character)
humanoid:TakeDamage(40)
else
CreateImpactEffect(hitPosition, hitNormal, hit)
end
bulletclone.Anchored = true --(this code added for debugging so nevermind)
end)
caster:Fire(m4origin, (mouseposition - m4origin), Bulletspeed, behaviour)
elseif Mag <= 0 and Reloading == false then
Reload()
end
task.wait(CoolTime_Each_Shot)
Guncool = false
end)









