I've been trying to make a gun using Raycasting and so far I have this...
Server:
local HeadshotSound = script.Parent.Pistol.Pistol.Headshot
local LimbsTable = {"Head", "Left Leg", "Right Leg", "Left Arm", "Right Arm"}
script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Pistol.Bolt.Position,(mousePos - script.Parent.Pistol.Bolt.Position)*300,raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model and hitPart.Name == "Head" then
model.Humanoid.Health -= 50
HeadshotSound:Play()
end
if model and hitPart.Name ~= "Head" then
model.Humanoid.Health -= 25
end
if model and hitPart.Name == LimbsTable then
print("A Limb has been hit")
end
end
end)
Client:
local mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
local StarterGUI = game.StarterGui
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
local FireSound = script.Parent.Pistol.Pistol.Fired
local ReloadSound = script.Parent.Pistol.Pistol.Reload
local NoAmmoSound = script.Parent.Pistol.Pistol.NoAmmo
local MouseIcon = "http://www.roblox.com/asset/?id=6398507484"
local MaxAmmo = 6
local CurrentAmmo = 6
script.Parent.Activated:Connect(function()
if CurrentAmmo > 0 then
script.Parent.Fire:FireServer(mouse.Hit.p)
FireSound:Play()
CurrentAmmo = CurrentAmmo - 1
PlayerGui.PistolAmmo.Frame.TextLabel.Text = CurrentAmmo .. "/6"
else
NoAmmoSound:Play()
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
ReloadSound:Play()
CurrentAmmo = MaxAmmo
wait(1.376)
PlayerGui.PistolAmmo.Frame.TextLabel.Text = CurrentAmmo .. "/6"
end
end)
script.Parent.Equipped:Connect(function()
mouse.Icon = MouseIcon
PlayerGui.PistolAmmo.Frame.Visible = true
end)
script.Parent.Unequipped:Connect(function()
mouse.Icon = ""
PlayerGui.PistolAmmo.Frame.Visible = false
end)
I want to make it so I can see if a limb or what limb has been hit with the raycast. I created a table with the names of the limbs and when I shoot the limbs I get no output. Unless a specify the limb directly.

3 comments
I've changed the code to this https://i.imgur.com/zxdYs9C.png. When I shoot a limb it still does not print "A limb has been hit" instead it prints "A limb has not been hit".
You may have to use a generic loop, then.
Okay thankyou that worked