Shooting Backwards:
Hello. I wish to prevent backwards shooting, whenever the mouse is located behind the player, however I haven’t found the solutions for it. Here is what I wish to prevent basically:
The issue is that the code I am using isn’t really working, as it gives an error in the output. I’ve tried “messing” with the code, however nothing helped.
Error:
https://gyazo.com/92c09641570fbb8db8d187794c5acd65
^Line 23
Server Script:
local SmallFireball = game.ReplicatedStorage.FireBall.SmallFireball
local Fireball = game.ServerStorage.Fireball
local Speed = 40
local Debounce = {}
SmallFireball.OnServerEvent:Connect(function(Player, mousePos, Handle)
if table.find(Debounce, Player) then return end
local HumanoidRootPart = Player.Character.Humanoid.RootPart
local rightArm = Player.Character["Right Arm"]
table.insert(Debounce, Player)
local Distance = 200
local Origin = Handle
local Start = Origin.CFrame.p
local Direction = (CFrame.new(Start,Vector3.new(mousePos.X, mousePos.Y, Player.Character.HumanoidRootPart.Position.Z))).lookVector
local params = RaycastParams.new()
params.FilterDescendantsInstances = {Handle, rightArm, Player.Character}
params.FilterType = Enum.RaycastFilterType.Blacklist
local raycastresult = workspace:Raycast(Start,Direction * Distance,params)
local lookVector = (Player.Character.HumanoidRootPart).lookVector --Line 23
local shootVector = Direction
local dotProduct = Direction:Dot(lookVector)
if dotProduct < 0 then return end
local Fireball2 = Fireball:Clone()
Fireball2.CFrame = rightArm.CFrame * CFrame.new(0, -(rightArm.Size.Y/2 + Fireball2.Size.Y + 1), 0)
Fireball2.Parent = workspace
local BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = Fireball2
BodyVel.MaxForce = Vector3.new(1,1,0) * 30000
BodyVel.Velocity = Direction * Speed
Event = Fireball2.Touched:Connect(function(Hit)
local ParentHit = Hit.Parent
local Humanoid = ParentHit:FindFirstChild("Humanoid")
if not Humanoid then return end
if ParentHit == Player.Character then return end
Humanoid:TakeDamage(math.random(15, 30))
Event:Disconnect()
Fireball2:Destroy()
end)
wait(0.8)
if Fireball2 then
Fireball2:Destroy()
end
delay(0.25, function()
if not Player then return end
table.remove(Debounce, table.find(Debounce, Player))
end)
end)
I’ve tried viewing a lot of topics regarding this issue including the following, however I have found no luck. If anyone is able to help me, it is appreciated.