How do I detect when a player gets hit by and explosion and dies (UNSOLVED)

I am making a game and I need to detect when a player gets hit with an explosion and send a remote event here is my code so far:

Server Script

local function explode()
	bombPart.CanCollide = false
	bombPart.BrickColor = red
	task.wait(.6)
	bombPart.CanCollide = true
	click:Play()
	bombPart.BrickColor = black
	task.wait(.6)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.7)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.6)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.5)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.5)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.5)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.4)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.3)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.2)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.2)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.1)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.1)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.1)
	click:Play()
	bombPart.BrickColor = red
	boom:Play()
	explosion.Position = script.Parent.Position
	explosion.Parent = script.Parent
	Debris:AddItem(script.Parent, 1)
end

explode()

And this is the local script that is receiving the remote event:

Local Script:

local textClone = script:WaitForChild('KilledPlayerText'):Clone()
local frame = script.Parent
local event = game:WaitForChild('ReplicatedStorage'):WaitForChild("Events"):WaitForChild('RemoteEvents'):WaitForChild('GameEvents'):WaitForChild('PlayerKilledBombEvent')
local debris = game:GetService("Debris")


local function change(plrName)
	print(plrName.." Event Fired!")
	textClone.Text = "You Have Killed "..plrName.."!"
	textClone.Name = "Killed "..plrName
	textClone.Parent = frame
	textClone.Visible = true
	task.wait(2.75)
	debris:AddItem(textClone, 0.01)
end

event.OnClientEvent:Connect(change)

Can you try this? Also add players and event variable.

local function explode()
	bombPart.CanCollide = false
	bombPart.BrickColor = red
	task.wait(.6)
	bombPart.CanCollide = true
	click:Play()
	bombPart.BrickColor = black
	task.wait(.6)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.7)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.6)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.5)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.5)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.5)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.4)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.3)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.2)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.2)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.1)
	click:Play()
	bombPart.BrickColor = red
	task.wait(.1)
	click:Play()
	bombPart.BrickColor = black
	task.wait(.1)
	click:Play()
	bombPart.BrickColor = red
	boom:Play()
	explosion.Position = script.Parent.Position
	explosion.Parent = script.Parent
	
	explosion.Hit:Connect(function(basepart)
		for i,v in pairs(Players:GetPlayers()) do
			if basepart.Parent.Name == v.Name then
				local Player = Players:GetPlayerFromCharacter(v)
				event:FireClient(Player)
			end
		end
	end)
	Debris:AddItem(script.Parent, 1)
end

explode()

I actually found a fix to the issue sightly before you commented and forgot to close this here is the code if ur interested:

local function detect(part)
	local plr = game.Players:GetPlayerFromCharacter(part.Parent)
	local val_plr = tostring(val.Value)
	local targetPlr = game.Players:FindFirstChild(val_plr)
	if plr and targetPlr then
		plr.Character.Humanoid:TakeDamage(100)
		local humanoid = plr.Character:FindFirstChild("Humanoid")
		if humanoid and humanoid.Health <= 1 then
			event:FireClient(targetPlr, plr.Name)
		end
	end
end

explosion.Hit:Connect(detect)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.