Quick actions

cmd+k|ctrl+k

Navigation

Languages

flashbang

Snippet info

Language

Lua

Visibility

public

Author

lazarovalkyrie

Created

2024-04-01T01:00:55.293318Z

Updated

2024-04-01T01:00:55.293318Z

local plr = owner
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")
local torso = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
local tool = Tool0
local handle = Part1

Tool0 = Instance.new("Tool")
Part1 = Instance.new("Part")
SpecialMesh3 = Instance.new("SpecialMesh")
Tool0.Name = "Flash Bang"
Tool0.CanBeDropped = false
Tool0.Parent = plr:FindFirstChild("Backpack")
Part1.Name = "Handle"
Part1.Parent = Tool0
Part1.Size = Vector3.new(0.7, 1.56, 0.65)
Part1.BottomSurface = Enum.SurfaceType.Smooth
Part1.Anchored = false
Part1.CanCollide = false
Part1.Material = Enum.Material.SmoothPlastic
Part1.TopSurface = Enum.SurfaceType.Smooth
Part1.CustomPhysicalProperties = PhysicalProperties.new(0.699999988, 1.5, 0.5, 2, 1)
SpecialMesh3.Parent = Part1
SpecialMesh3.MeshId = "rbxassetid://454819719"
SpecialMesh3.Scale = Vector3.new(0.002, 0.002, 0.002)
SpecialMesh3.TextureId = "rbxassetid://454819722"
SpecialMesh3.MeshType = Enum.MeshType.FileMesh

local plr = Tool0.Parent.Parent
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")
local torso = char['Torso'] or char['UpperTorso']
local tool = Tool0
local handle = Part1

local debris = game:GetService("Debris")
local tween = game:GetService("TweenService")

local using = false
local equipped = false
local holding = false
local amount = 1/0

local junk = script

local hits = {1543854566,1543854764,1543854943,1543855404}
local explosions = {2814354886,2814355346,2814355743,2814354338}

local ls = [[
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character

local ScreenGui0 = Instance.new("ScreenGui")
ScreenGui0.DisplayOrder = 10
ScreenGui0.IgnoreGuiInset = true
local Frame1 = Instance.new("Frame")
ScreenGui0.Parent = script.Parent.Parent:FindFirstChildOfClass("PlayerGui")

local flashed = Instance.new("Sound")
flashed.Parent = ScreenGui0
flashed.Looped = true
flashed.Volume = 2
flashed.SoundId = 'rbxassetid://9069161602'
flashed:Play()

ScreenGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
Frame1.Parent = ScreenGui0
Frame1.Size = UDim2.new(1, 0, 1, 0)
Frame1.BackgroundColor = BrickColor.new("Institutional white")
Frame1.BackgroundColor3 = Color3.new(1, 1, 1)
Frame1.ZIndex = 2

local power = 0
local pos = script:WaitForChild('pos').Value
local t = 5
local t2 = 2

local camera = workspace.CurrentCamera

local distance = pos-camera.CFrame.Position
local direction = distance/distance.Magnitude 

power = direction:Dot(camera.CFrame.LookVector)

local max_dist = 150
local multiplier = math.clamp(distance.Magnitude,0,max_dist)/max_dist
multiplier = 1-multiplier

if 0 > power then
	power = math.abs(power)
	t = (1-power)*(5*multiplier)
	t2 = (1-power)*(2*multiplier)
else
	t = (5*multiplier)
	t2 = (2*multiplier)
end

local ViewportFrame = Instance.new("ViewportFrame", ScreenGui0)
ViewportFrame.Size = UDim2.new(1, 0, 1, 0)
ViewportFrame.BackgroundTransparency = 1
ViewportFrame.ImageTransparency = 0.2

local ViewportCamera = Instance.new("Camera", ViewportFrame)
ViewportFrame.CurrentCamera = ViewportCamera
ViewportCamera.CFrame = workspace.CurrentCamera.CFrame
for i,v in pairs(workspace:GetChildren()) do
	if (v.ClassName == "Part" or v.ClassName == "MeshPart" or v.ClassName == "Model" or v.ClassName == "Folder") and not script:IsDescendantOf(v) and v ~= char then
		v.Archivable = true
		local vclone = v:Clone()
		for i,m in pairs(vclone:GetDescendants()) do
			if m:IsA("ScreenGui") then
				m:Destroy()
			end
			m.Name = ' '
		end
		vclone.Parent = ViewportFrame
		if vclone:findFirstChildOfClass("Script") then
			vclone:findFirstChildOfClass("Script").Disabled = true
		end
		if vclone:findFirstChildOfClass("LocalScript") then
			vclone:findFirstChildOfClass("LocalScript").Disabled = true
		end
	end
end

spawn(function()
	wait(t2)
	game:GetService("TweenService"):Create(flashed,TweenInfo.new(t),{Volume = 0}):Play()
	game:GetService("TweenService"):Create(Frame1,TweenInfo.new(t),{BackgroundTransparency = 1}):Play()
	wait(t/4)
	game:GetService("TweenService"):Create(ViewportFrame,TweenInfo.new(t),{ImageTransparency = 1}):Play()
end)

game:GetService("Debris"):AddItem(ViewportFrame,t+1)
game:GetService("Debris"):AddItem(ScreenGui0,t*2)
]]

function play(id,par,vol,pitch,loop,starting,ending)
	local current = Instance.new("Sound",par)
	current.SoundId = "rbxassetid://" ..id
	current.Parent = par or script
	current.Volume = vol or 1
	current.PlaybackSpeed = pitch or 1
	current.Looped = loop or false
	current:Play()
	current.TimePosition = starting or 0
	spawn(function()
		if ending ~= nil and tonumber(ending) then
			repeat wait() until current.TimePositon >= ending
			current:Stop()
			debris:AddItem(current,1)
		else
			repeat wait() until not current.IsPlaying
			debris:AddItem(current,1)
		end
	end)
	return current
end

function effect(par,p)
	local cval = Instance.new("ObjectValue")
	cval.Name = 'flashed'
	cval.Parent = par
	game:GetService("Debris"):AddItem(cval,0.2)
	for i,v in pairs(game:GetService("Players"):GetChildren()) do
		if v.Name == par.Name then
			local s = NLS(ls,v:FindFirstChild("Backpack"))
			local bval = Instance.new("Vector3Value")
			bval.Name = 'pos'
			bval.Value = p
			bval.Parent = s
		end
	end
end

function bang(par,pos)
	local Part0 = Instance.new("Part")
	Part0.Name = "grenade"
	Part0.Parent = par
	Part0.Position = pos
	Part0.Transparency = 1
	Part0.Size = Vector3.new(4, 0.0500000007, 4)
	Part0.Anchored = true
	Part0.BottomSurface = Enum.SurfaceType.Smooth
	Part0.CanCollide = false
	Part0.Locked = true
	Part0.TopSurface = Enum.SurfaceType.Smooth
	play(explosions[math.random(1,#explosions)],Part0,1)
	local s = 150
	local hitbox = Instance.new("Part",Part0)
	hitbox.Name = "hit box"
	hitbox.Size = Vector3.new(s,s,s)
	hitbox.CanCollide = false
	hitbox.Anchored = true
	hitbox.Transparency = 1
	hitbox.Position = pos
	--local reg = Region3.new(hitbox.Position-hitbox.Size/2,hitbox.Position+hitbox.Size/2)
	--local parts = workspace:FindPartsInRegion3(reg,hitbox,1/0)
	--for _,obj in pairs(parts) do
	for i,v in pairs(game:GetService("Players"):GetPlayers()) do
		local targchar,tarhum,targtorso,targhead
		pcall(function()
			targchar = v.Character --obj.Parent
		end)
		pcall(function()
			tarhum = targchar:FindFirstChildOfClass("Humanoid")
		end)
		pcall(function()
			targtorso = targchar:FindFirstChild("HumanoidRootPart") or targchar:FindFirstChild("Torso")
		end)
		pcall(function()
			targhead = targchar:FindFirstChild("Head")
		end)
		if targchar and tarhum and tarhum.Parent and targtorso and targtorso.Parent and targhead then
			local p1 = pos+Vector3.new(0,1,0)
			local p2 = (targhead.Position-p1)
			local chars = {}
			for i,vv in pairs(workspace:GetChildren()) do
				local targchar2,tarhum2,targtorso2
				pcall(function()
					targchar2 = vv --obj.Parent
				end)
				pcall(function()
					tarhum2 = targchar2:FindFirstChildOfClass("Humanoid")
				end)
				pcall(function()
					targtorso2 = targchar2:FindFirstChild("HumanoidRootPart") or targchar2:FindFirstChild("Torso")
				end)
				if targchar2 and tarhum2 and tarhum2.Parent and targtorso2 and targtorso2.Parent then
					table.insert(chars,targchar2)
				end
			end
			local params = RaycastParams.new()
			params.IgnoreWater = true
			params.FilterType = Enum.RaycastFilterType.Exclude
			params.FilterDescendantsInstances = {script,Part0,targchar,unpack(chars),junk}
			local blocked = false
			local hit = workspace:Raycast(
				p1,
				p2.Unit*p2.Magnitude,
				params
			)
			if hit and 0.5 > hit.Instance.Transparency then
				blocked = true
			end
			if not targchar:FindFirstChild("flashed") and targchar:IsA("Model") and not blocked then
				effect(targchar,hitbox.Position)
			end
		end
	end
	local light = Instance.new("PointLight")
	light.Brightness = 40
	light.Range = s/2
	light.Shadows = true
	light.Parent = Part0
	game:GetService("TweenService"):Create(light,TweenInfo.new(0.25),{Brightness = 0}):Play()
	spawn(function()
		wait(0.25)
		debris:AddItem(Part0,5)
		hitbox:Destroy()
	end)
end

function throw(mpos)
	local pag = Instance.new("Part")
	pag.Parent = junk
	pag.CanCollide = false
	pag.Transparency = 1
	pag.Anchored = true
	pag.CanCollide = false
	pag.CFrame = CFrame.new(handle.Position,mpos)
	
	--play('2552682980',torso,1)
	play('711753382',handle,1)

	local fake = handle:Clone()
	fake.Parent = junk
	fake.Name = "grenade"
	fake.CanCollide = true
	fake.Velocity = pag.CFrame.lookVector * 130
	
	local hit = Instance.new("Sound")
	hit.SoundId = "rbxassetid://" .. tostring(hits[math.random(1,#hits)])
	hit.Parent = fake
	hit.Volume = 1
	
	local bouncing = false
	local activated = false
	
	fake.Touched:Connect(function(obj)
		if obj and not bouncing then
			bouncing = true
			hit.SoundId = "rbxassetid://2552417180"-- .. tostring(hits[math.random(1,#hits)])
			hit:Play()
			spawn(function()
				wait(.1)
				bouncing = false
			end)
			if not activated then
				activated = true
				spawn(function()
					wait(1.5)
					bang(junk,fake.Position)
					fake:Destroy()
					pag:Destroy()
				end)
			end
		end
	end)
end

tool.Equipped:Connect(function()
	equipped = true
end)
tool.Unequipped:Connect(function()
	equipped = false
end)

local remote = script:FindFirstChild('RemoteEvent') or Instance.new("RemoteEvent")
remote.Parent = plr:FindFirstChildOfClass("Backpack")

remote.OnServerEvent:Connect(function(lplr,data)
	if plr == lplr and data then else return end
	if equipped and not using then
		using = true
		throw(data)
		amount -= 1
		if 0 >= amount then
			tool:Destroy()
		end
		wait(0.25)
		using = false
	end
end)

NLS([[
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local remote = script.Parent
mouse.Button1Down:Connect(function()
	remote:FireServer(mouse.Hit.p)
end)
]],remote)
INFO