Hello there! I was wondering why your own gun does damage to you instead of your target, like a dummy for example. This is really something that I don't know how to script, so I would appreciate it if I got some help; Thanks! More Info below!
-- Variables
local TweenService = game:GetService("TweenService")
local Tweeninfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
-- Scripting in Action
script.Parent.ShootEvent.OnServerEvent:Connect(function(player, caster, position)
local rayOrigin = caster.Position
local rayDirection = position
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {player.Character}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = game.Workspace:Raycast(rayOrigin, (position - script.Parent.Handle.Position) * 200, rayParams)
local hittedPart = rayResult.Instance
local bullet = Instance.new("Part", game.Workspace)
bullet.Size = Vector3.new(0.25, 0.25, 0.25)
bullet.Shape = Enum.PartType.Cylinder
bullet.Position = script.Parent.PistolModel.Flash.Position
bullet.BrickColor = BrickColor.new("Gold")
local TweenTo = {CFrame = CFrame.new(position)}
local TweenBullet = TweenService:Create(bullet, Tweeninfo, TweenTo)
TweenBullet:Play()
if hittedPart.Parent:IsA("Model") then
bullet.Touched:Connect(function(hit)
local charcter = hit.Parent
local humanoid = charcter:FindFirstChild("Humanoid")
if humanoid then
bullet:Destroy()
if hittedPart.Name == "Head" then
humanoid:TakeDamage(25)
print("Headshot Acquired!")
else
humanoid:TakeDamage(16)
print("Shot!")
end
else
wait(5)
bullet:Destroy()
end
end)
end
end)

1 comment
I don't really use tweenservice but I made a gun thats easy to script, It may not be based off the problem you have having but can I show It to you?