shooting = false
reloadtime = 0
time = 0
bin=script.Parent
function nohealth()
reloadtime = 0
shooting = false
mouse.Icon = "rbxasset://textures\\GunCursor.png"
end
function CheckDistance(part1,part2)
if (part1~=nil and part2~=nil) then
local x1=part1.Position.x
local y1=part1.Position.y
local z1=part1.Position.z
local x2=part2.Position.x
local y2=part2.Position.y
local z2=part2.Position.z
local dist=(math.abs(x1-x2)+math.abs(y1-y2)+math.abs(z1-z2))/3 --Average Position?
if (dist<=20) then
return true
else
return false
end
else
return false
end
end
function onButton1Down(mouse)
if reloadtime > 0 then return end
if shooting == true then return end
reloadtime = 1.0
shooting = true
time = 0
while shooting == true do
--FIRE MECHANISM
local part = mouse.Target
if (part~=nil) then
if (CheckDistance(game.Players.LocalPlayer.Character.Head,part)==false) then break end
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local health = h.Parent:findFirstChild("Health")
h.Parent.Health:remove()
local tpos = h.Parent.Torso.CFrame
local b = Instance.new("BodyPosition")
b.Parent = h.Parent.Torso
b.maxForce = Vector3.new(400000,400000,400000)
b.position = Vector3.new(tpos.x, tpos.y + 7, tpos.z)
wait(0.2)
h.Health = 90
wait(0.2)
h.Health = 80
wait(0.2)
h.Health = 70
wait(0.2)
h.Health = 60
wait(0.2)
h.Health = 50
wait(0.2)
h.Health = 40
wait(0.2)
h.Health = 30
wait(0.2)
h.Health = 20
wait(0.2)
h.Health = 10
wait(0.2)
h.Health = 0
b:remove()
else
break
end
end
wait(0.5)
time = time + 0.5
if time > 500 then shooting = false end
end
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
wait(3)
reloadtime = 0
mouse.Icon = "rbxasset://textures\\GunCursor.png"
end
function onButton1Up(mouse)
shooting = false
end
function onSelected(mouse)
if reloadtime > 0 then
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
else
mouse.Icon = "rbxasset://textures\\GunCursor.png"
end
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Button1Up:connect(function() onButton1Up(mouse) end)
end
bin.Selected:connect(onSelected)
|