Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Players wont die?

Asked by 9 years ago

Hey guys, here's a script for a weapon I made. What's going on now is that the person who got shot wont die. It was working perfectly fine before I added the tagging. But I really urgently need tagging to be in the script. I have no idea whats going on! Plelase help!!

Script:

local debris = game:GetService("Debris")
local tuple = {...}
local playerhit = tuple[3]
local targethumanoid = playerhit.Parent:FindFirstChild("Humanoid")
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local market = game:GetService("MarketplaceService")
local turnRate = 36
local mouse
local idleAnim
local humanoid
local player

while not player do
if script.Parent.Parent:IsA("Model") then
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
elseif script.Parent.Parent:IsA("Backpack") then
player = script.Parent.Parent.Parent 
end
wait()
end

function RayIgnoreCheck(hit, pos)
if hit and (hit.Transparency > 0 or hit.Name == "Bullet" or hit.Name == "Handle" or hit:IsDescendantOf(char)) then
return true
end
return false
end

function RayCast(startPos, vec, rayLength)
local hitObject, hitPos = game.Workspace:FindPartOnRay(Ray.new(startPos + (vec * .01), vec * rayLength), Handle)
if hitObject and hitPos then
local distance = rayLength - (hitPos - startPos).magnitude
if RayIgnoreCheck(hitObject, hitPos) and distance > 0 then
return RayCast(hitPos, vec, distance)
end
end
return hitObject, hitPos
end

local function CreateBullet(bulletPos)
local bullet = Instance.new("Part")
bullet.CanCollide = false
bullet.Anchored = true
bullet.Name = "Bullet"
bullet.Transparency = 1
bullet.Parent = workspace
bullet.CFrame = CFrame.new(bulletPos)
game:GetService("Debris"):AddItem(bullet, 2.5)
local g = script.Bullet:clone()
g.Parent = bullet
g.Img.Script.Disabled = false
game:GetService("Debris"):AddItem(Instance.new("PointLight",bullet),0.2)
return bullet
end

function getGrip()
if char then
if char:findFirstChild("Right Arm") then
if char["Right Arm"]:findFirstChild("RightGrip") then
return char["Right Arm"].RightGrip
end
end
end
end

function ReloadAnim(spinRate)
delay(0.1,function ()
local grip = getGrip()
if grip then
local originalGrip = grip.C0
for i = 1,spinRate do 
grip.C0 = grip.C0 * CFrame.fromEulerAnglesXYZ(math.pi/(spinRate/4),0,0)
wait()
end
grip.C0 = originalGrip
end
end)
RELOAD_ANIM = humanoid:LoadAnimation(script.Parent.Reload)
RELOAD_ANIM:Play(0.1,1,spinRate < 36 and 3 or 2)
Handle.Reload:Play()
end

function Shoot(player,target)
if not Tool.Enabled then return end
if not humanoid then return end
Tool.Enabled = false
Handle.FireSound:Play()
humanoid:LoadAnimation(script.Parent.FireAni):Play()
local hitObject, bulletPos = RayCast(Handle.Position,CFrame.Angles((.5-math.random())*2*.05,(.5-math.random())*2*.05,(.5-math.random())*2*.05)*((target - Handle.Position).unit), 400)
if hitObject then
CreateBullet(bulletPos)
if hitObject.Parent then
local hitHumanoid = hitObject.Parent:findFirstChild("Humanoid")
if hitHumanoid and game.Players:GetPlayerFromCharacter(hitHumanoid.Parent) ~= player then
local tag = Instance.new("ObjectValue") -- Tagging
tag.Name = "creator"
tag.Value = player
debris:AddItem(tag, 3)
tag.Parent = hitHumanoid
hitHumanoid.Health = 0 -- Kill person who got shot
end
end 
end
wait(1)
ReloadAnim(turnRate)
wait(turnRate/12)
Tool.Enabled = true
end

local fireInput = script.Parent:WaitForChild("FireWeapon")
fireInput.OnServerEvent:connect(Shoot)

function OnEquipped(m)
char = script.Parent.Parent
humanoid = char:WaitForChild("Humanoid")
mouse = m
end

function OnUnequipped()
mouse = nil
end

Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)

Answer this question