Need help with getting the part position

Need help with getting the part position and then positioning the child of the part to the parent… that sounds complicated lol.

Also couldn’t find anything useful on the web

Here is the code:

local mine = script.Parent
local minePosition = mine.CFrame.Position -- ????????? No idea how to get the part position
local humanoid = game:GetService("Humanoid")
local boom = Instance.new("Explosion")
boom.Visible = false

mine.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
		boom.Parent = mine
		boom.Position = Vector3.new(minePosition) --Telling the explosion to position itself in the mine
		boom.Visible = true
	end
end)

2 Likes

Maybe add the boom inside the touch function

2 Likes
local mine = script.Parent
local minePosition = mine.CFrame.Position
local humanoid = game:GetService("Humanoid")

mine.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
		local boom = Instance.new("Explosion")
		boom.Visible = false
		boom.Parent = mine
		boom.Position = minePosition
		boom.Visible = true
	end
end)

minePosition is already a Vector3, so you do not need to put it into another Vector3 constructor.
Also, you shouldn’t be creating the explosion early, because it automatically deletes itself.
Also also, if the position of the mine changes, you should also not get it early either, instead getting it inside the function.

2 Likes
local mine = script.Parent
local humanoid = game:GetService("Humanoid")

mine.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0

        local boom = Instance.new("Explosion")
		boom.Position = mine.Position
		boom.Visible = true
        boom.Parent = mine
	end
end)
2 Likes

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