Hello! I am trying to make a gun for my game, and for the most part its going well! However, when I try to add bullets for it, it seems to not work. The bullets don’t go in the right direction, and aren’t rotated correctly. And the raycasting doesn’t have the player take damage, even though it does without the bullet.
Video:
Bullet code:
local bullet = RS:WaitForChild("Bullet")
local new_bullet = bullet:Clone()
new_bullet.Anchored = false
new_bullet.CanCollide = false
new_bullet.Position = handle["Model12&@321"].FIRE_AREA.Position
new_bullet.Parent = game.Workspace
DEBRIS:AddItem(new_bullet, 4)
new_bullet.Velocity = new_bullet.CFrame.LookVector * speed
local character = player.Character
--Raycasting
local ray_params = RaycastParams.new()
ray_params.FilterType = Enum.RaycastFilterType.Blacklist
ray_params.FilterDescendantsInstances = {character}
local raycast_result = workspace:Raycast(handle["Model12&@321"].FIRE_AREA.Position, (mouse_pos - handle["Model12&@321"].FIRE_AREA.Position) * 300, ray_params)
if raycast_result then
local instance = raycast_result.Instance
local model = instance:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
if instance.Name == "Head" then
headshot_sound:Play()
model:FindFirstChild("Humanoid"):TakeDamage(25)
else
model:FindFirstChild("Humanoid"):TakeDamage(15)
end
end
end
end
Any help will be appreciated