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)
The problem it's that inside the Raycast params, you should put instead of the model, the childrens, or atleast the ones that can get hitted by the ray using :GetChildren()
. I'd recommend making a table and putting inside all the BaseParts
and Accessories
of the player. Also, where does the variable position
come from?
Edit: I marked your answer correct, I've used another source of information to help out with my scripting problem, a DevForum post, but anyway thanks for trying to help! I really appreciate it!