local tool = script.Parent
local animation = script.headhot
local random = math.random(30,35)
local player
tool.Equipped:Connect(function()
tool.Handle.Sound:Play()
local character = tool.Parent
player = game.Players:GetPlayerFromCharacter(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
script.Parent.LocalScriptglock.Enabled = false
script.Enabled = false
end)
end)
tool.Unequipped:Connect(function()
player = nil
end)
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
game:GetService("Debris"):AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
script.Parent.Shoot.OnServerEvent:Connect(function(player, direction)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(tool.Handle.Barrel.Position, direction * 196.3, raycastParams)
while raycastResult and raycastResult.Instance:IsA("Accessory") do
raycastResult = workspace:Raycast(raycastResult.Position, (direction - raycastResult.Position).Unit * 196.3, raycastParams)
end
local origin = tool.Handle.Barrel.Position
local distance = 194.8
while raycastResult and raycastResult.Instance.Material == Enum.Material.Foil do
local newOrigin = raycastResult.Position + (direction * 0.1)
local remainingDistance = distance - (newOrigin - origin).Magnitude
origin = newOrigin
raycastResult = workspace:Raycast(origin, direction * remainingDistance, raycastParams)
end
while raycastResult and raycastResult.Instance.Name == "fence" do
local newOrigin = raycastResult.Position + (direction * 0.1)
local remainingDistance = distance - (newOrigin - origin).Magnitude
origin = newOrigin
raycastResult = workspace:Raycast(origin, direction * remainingDistance, raycastParams)
end
if raycastResult then
local raycastInstance = raycastResult.Instance
local model = raycastInstance:FindFirstAncestorOfClass("Model")
local humanoid = model and model:FindFirstChildWhichIsA("Humanoid")
if humanoid then
TagHumanoid(humanoid, player)
if raycastInstance.Name == "Head" then
local anmier = model:FindFirstChild("Humanoid"):WaitForChild("Animator")
local play = anmier:LoadAnimation(animation)
humanoid:TakeDamage(67)
play:Play()
script.Parent.Handle.hit:Play()
elseif raycastInstance.Name == "neckshot" then
local partic = raycastInstance:WaitForChild("blod")
humanoid:TakeDamage(100)
script.Parent.Handle.hit:Play()
if partic.Enabled == false then
partic.Enabled = true
partic:Emit(100)
if model:WaitForChild("Head") then
local bloodface = game:GetService("ServerStorage"):WaitForChild("bloodface"):Clone()
bloodface.Parent = model:WaitForChild("Head")
local sounds = game:GetService("ServerStorage"):WaitForChild("Vomit Disgusting Coughing Wet Various Versio (SFX)"):Clone()
sounds.Parent = model:WaitForChild("Head")
sounds:Play()
task.wait(0.5)
end
end
else
humanoid:TakeDamage(random)
script.Parent.Handle.hit:Play()
end
end
UntagHumanoid(humanoid)
end
end)
headshot doesnt work mostly and i have no idea why
if humanoid then
TagHumanoid(humanoid, player)
local playr = game.Players:GetPlayerFromCharacter(model)
local tragetteam = game:GetService("Teams"):WaitForChild("raider")
if playr.Team == tragetteam then
if raycastInstance.Name == "Head" then
humanoid:TakeDamage(54)
print("ok pea its head ")
local anmier = model:FindFirstChild("Humanoid"):WaitForChild("Animator")
local play = anmier:LoadAnimation(animation)
play:Play()
script.Parent.Handle.hit:Play()
else
humanoid:TakeDamage(random)
script.Parent.Handle.hit:Play()
end
end
end
UntagHumanoid(humanoid)
end
end)
i made a team gun for only damages players in raider team and it doesnt damage the player in roblox when they are in team raider