Can't get a Bomb to Explode when a Tool is Activated

Hello fellow developers. I have a problem where the character doesn’t die from a bomb placed in their HumanoidRootPart. How I am trying to get it to work is when you click on a player with the tool, it sends a message to the server, placing the bomb in the HRP and then making the bomb blow. I have tried for hours to get it to work, but no luck. Here are the scripts:

-- local script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()
	local target = mouse.Target
	if target then
		if target.Parent:FindFirstChild("Humanoid") then
			print(target)
			local nplayer = target.Parent
			game.ReplicatedStorage.BigBomb:FireServer(target.Parent)
		end
	end
end)

-- server script
game.ReplicatedStorage.BigBomb.OnServerEvent:Connect(function(player)
	local Bomb = Instance.new("Explosion", workspace)
	Bomb.Position = player.HumanoidRootPart.CFrame.Position or player:FindFirstChild("Character").HumanoidRootPart.CFrame.Position
	Bomb.BlastRadius = 8
	wait(1)
	Bomb:Destroy()
end)

Also I got this error when activating the tool.

HumanoidRootPart is not a valid member of Player “Players.Kamlkaze_Kid”

Thanks for reading.

you gotta say player.Character.HumanoidRootPart…-- because player is not the character model which means the humanoidrootpart is in character sorry if i explain badly im not a type of person who can explain properly

-- server script
game.ReplicatedStorage.BigBomb.OnServerEvent:Connect(function(player)
	local Bomb = Instance.new("Explosion", workspace)
	Bomb.Position = player.Character.HumanoidRootPart.CFrame.Position or player:FindFirstChild("Character").HumanoidRootPart.CFrame.Position
	Bomb.BlastRadius = 8
	wait(1)
	Bomb:Destroy()
end)
1 Like

The error is pretty straightforward: There’s no HumanoidRootPart object inside the Player object (Or game.Players.Kamlkaze_Kid for your Instance)

You have to reference the Character using player.Character (Which is actually game.Workspace.KamIkaze_Kid) as @Creeperman16487 mentioned otherwise the script would not work, and the reason why the or statement won’t work is cause it’s already assuming that there’s a HumanoidRootPart part inside the Player object in the first conditional check

1 Like

is there a way to do this with dummies as well? I know you can’t use ‘character’ in this case.

The dummies are a character so you won’t have to use .character on them.

I know. Well anyway I will do this part on my own but thanks!

Ok I tried to apply this on dummies but it does not seem to work. Here is the script

game.ReplicatedStorage.BigBomb.OnServerEvent:Connect(function(player)
	local Bomb = Instance.new("Explosion", workspace)
	if player.Name == "Dummy" and player.Character == false then
		Bomb.Position = player.HumanoidRootPart.Position
		Bomb.BlastRadius = 8
		wait(1)
		Bomb:Destroy()
	else
		Bomb.Position = player.Character.HumanoidRootPart.CFrame.Position
		Bomb.BlastRadius = 8
		wait(1)
		Bomb:Destroy()
	end
end)

Try to parent the bomb to the humanoid root part

the same result, instead of the dummy dying, my character dies. Do i apply it to the other part of the if sentence

Apply it to the target character. You have to send it as an argument via remote

Send mouse.target as an argument and do the check on the server side. Then apply the bomb to the target player. Now what you do is that you apply the bomb to the player who sends the remote event which in this case is the player activating the tool. Basically your script kills the one activating the tool

Sorry, I do not want my character to die, but the dummy. I used the same local script above and the server script is this now:

game.ReplicatedStorage.BigBomb.OnServerEvent:Connect(function(player)
	local Bomb = Instance.new("Explosion", workspace)
	if player.Name == "Dummy" and player.Character == false then
		Bomb.Parent = player.HumanoidRootPart
		Bomb.Position = player.HumanoidRootPart.Position
		Bomb.BlastRadius = 8
		wait(1)
		Bomb:Destroy()
	else
		Bomb.Position = player.Character.HumanoidRootPart.CFrame.Position
		Bomb.Parent = player.Character.HumanoidRootPart
		Bomb.BlastRadius = 8
		wait(1)
		Bomb:Destroy()
	end
end)

the first part is if its a dummy and second is if its a player

The first parameter of a remote event is always the player who sent it, so you want to add another parameter to account for that. Also, you are sending the character that was hit, not the player that was hit, so you should just reference player.HumanoidRootPart, not player.Character.HumanoidRootPart

game.ReplicatedStorage.BigBomb.OnServerEvent:Connect(function(playerwhosentit, player)
	local Bomb = Instance.new("Explosion", workspace)
	if player.Name == "Dummy" and not player.Character then
		Bomb.Parent = player.HumanoidRootPart
		Bomb.Position = player.HumanoidRootPart.Position
		Bomb.BlastRadius = 8
		wait(1)
		Bomb:Destroy()
	else
		Bomb.Position = player.HumanoidRootPart.CFrame.Position
		Bomb.Parent = player.HumanoidRootPart
		Bomb.BlastRadius = 8
		wait(1)
		Bomb:Destroy()
	end
end)

Tested it and still kills me instead of the dummy

You’re trying to index something that belongs to the character, not the player. A rule of thumb is not to parent first before setting properties, because setting properties of an instance that isn’t parented is very cheap and for that reason is good practice.

Instead of explaining the reasons, you can just see it for your self: PSA: Don't use Instance.new() with parent argument

Also there is no need to call FindFirstChild on their character, their character should exist by the time the event is fired and if not, you can use utilize player.CharacterAdded:Wait().

game.ReplicatedStorage.BigBomb.OnServerEvent:Connect(function(player)
	local bomb = Instance.new("Explosion")
    bomb.BlastRadius = 8
	bomb.Position = player.Character.HumanoidRootPart.Position
    bomb.Parent = workspace	

	wait(1)
	Bomb:Destroy()
end)