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”
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)
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
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
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)
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.
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().