Hi, so I made a shot gun. The bullet spawns and rotates where I want it.
The problem is this:
If I move while shooting the bullet, the bullet kinda just get stuck there right in midair, I want the bullet to be at the gunpoint while I’m still moving is there a way to do that? Sorry is this is a little confusing I tried my best to explain.
You can use the raycasting to detect a player, you do not need a part for that. Make a beam it’s better and use raycastresult to detect if a humanoid touched or got in the way of the ray
You can use a beam like I said for a visual representation of the bullet shooting and always being at the gunpoint. Can I see your script that handles the weapon?
Alright, but how can I make the beam look like a part, can you show me an example?
Here’s the script:
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Plr.Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local Var = false
local Magnitude = (Pos - Handle.Position).Magnitude
if Magnitude < MaxDis then
for i = 1, 5 do
local Part = Instance.new("Part")
Part.Name = "Part"..i
Part.CanCollide = false
Part.Anchored = true
Part.Parent = game.Workspace.Placement
Part.Size = Vector3.new(0.1,0.1,Magnitude + 1)
Part.Color = Color3.fromRGB(255, 255, 0)
Part.Material = "Neon"
if Part.Name == "Part1" then
Part.CFrame =CFrame.lookAt(Handle.Parent.ShootBox.Position, Pos) * CFrame.new(0,0,-Magnitude/2)
else
Part.CFrame =CFrame.lookAt(Handle.Parent.ShootBox.Position, Pos + Vector3.new(math.random(-Spread/2, -1),0,math.random(1, Spread/2))) * CFrame.new(0,0,-Magnitude/2)
end
local RayCast = workspace:Raycast(Part.Position, Part.CFrame.LookVector * 25,Params)
if RayCast ~= nil then
local Humanoid = RayCast.Instance.Parent:FindFirstChild("Humanoid")
if Humanoid then
if not Var then
Humanoid.Health -= 60
Var = true
end
end
end
game.Debris:AddItem(Part, 0.1)
end
end
Just like this it would look. Just check the FaceCamera setting in the beam and it should looks something like this.
Your code would be something like this.
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Plr.Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local Var = false
local Magnitude = (Pos - Handle.Position).Magnitude
if Magnitude < MaxDis then
for i = 1, 5 do
local Part = Instance.new("Part")
local beam = Instance.new("Beam")
beam.Color = Color3.fromRGB(255,255,0)
beam.FaceCamera = true
local attach1 = Instance.new("attachment")
attach1.Parent = Part
local attach2 = Instance.new("attachment")
Part.Name = "Part"..i
Part.CanCollide = false
Part.Anchored = true
Part.Parent = game.Workspace.Placement
Part.Size = Vector3.new(0.1,0.1,0.1)
Part.CFrame = CFrame.new(Pos)
attach2.Parent = Part
beam.Attachment0 = attach1
beam.Attachment1 = attach2
beam.Enabled = true
beam.Parent = Handle
end
local RayCast = workspace:Raycast(Part.Position, Part.CFrame.LookVector * 25,Params)
if RayCast ~= nil then
local Humanoid = RayCast.Instance.Parent:FindFirstChild("Humanoid")
if Humanoid then
if not Var then
Humanoid.Health -= 60
Var = true
end
end
end
game.Debris:AddItem(Part, 0.1)
end
end
I don’t know if this would work since I don’t fully understand where are the variables like Part come from!