How do i make player explode when part touched?

How do i make player explode when part touched?

I already made the script for it but didn’t work

local player=game:GetService("Players").LocalPlayer
local  char=player.Character or player.CharacterAdded:Wait()
local h=char:WaitForChild("HumanoidRootPart")

script.Parent.Touched:Connect(function(hit)
	local explosion=Instance.new("Explosion",workspace)
	
	explosion.Position=Vector3.new(h.Position)
	
end)

Question, where is this localscript?

why are you making a new vector3 value, you can just do

explosion.Position = h.Position

Inside part that i want to be touched

And where is that part located exactly?

the part was located in workspace

That explains why this script doesn’t work. Localscripts don’t run if they are a descendant of workspace and not parented by a character model.

1 Like

Where should i put the script?StarterPlayer?

why did u used Local Player in script? it should be script and u should add

script.Parent.Touched:Connect(function(hit)
        if hit:FindFirstChildWhichIsA("Humanoid") then
              local explosion=Instance.new("Explosion",workspace)
	
	      explosion.Position=Vector3.new(h.Position)
        end
end)

It’s a localscript, not serverscript.

1 Like

You should put it in StarterCharacter and detect if any of the character parts is touching that part by using Humanoid.Touched event and checking it from there.

1 Like
script.Parent.Touched:Connect(function(hit)
        if hit:FindFirstChildWhichIsA("Humanoid") then
              local explosion=Instance.new("Explosion",workspace)
	
	      explosion.Position= hit.Position
        end
end) 

that will work Put it in script and the script into the part that u want to explode

1 Like

Thank you so much.Its now working just like i wanted