Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Block spawns on my head instead of torso?

I'm trying to make a shockwave effect, and I want to make the meshpart spawn in my torso, but when I set it to the torso's position, It spawns above my head?

plr = game.Players.LocalPlayer
char = plr.Character
mouse = plr:GetMouse()
Instance.new("ForceField", char)


function die()
	plr = game.Players.LocalPlayer
    char = plr.Character
	local ex = Instance.new("Part", game.Workspace)
	local mesh = Instance.new("SpecialMesh", ex)
	ex.Position = char.Torso.Position
	mesh.MeshId = "http://www.roblox.com/asset/?id=20329976"
	ex.CanCollide = false
	ex.BrickColor = BrickColor.new("Gold")
end
mouse.Button1Down:connect(die)

EDIT:::: I've tried this aswell but it still doesn't work.

plr = game.Players.LocalPlayer
char = plr.Character
mouse = plr:GetMouse()
Instance.new("ForceField", char)


function die()
	plr = game.Players.LocalPlayer
    char = plr.Character
	local ex = Instance.new("Part", game.Workspace)
	local mesh = Instance.new("SpecialMesh", ex)
	ex.Position = char.Torso.Position + Vector3.new(0, -5, 0)
	mesh.MeshId = "http://www.roblox.com/asset/?id=20329976"
	ex.CanCollide = false
	ex.BrickColor = BrickColor.new("Gold")
end
mouse.Button1Down:connect(die)

2 comments

0

Since you can't collide with your object, it can't really go into your torso. Try setting CanCollide to true (before you define the position as well)

0

I tried it but it is still spawning above my head.

1 answer

✓ Accepted answer

When you set the Position property of a part, the game will move the object above any parts in the way.

To evade this, set the CFrame of the part instead.

So you can replace line 12 of the original code with this:

ex.CFrame = CFrame.new(char.Torso.Position) -- set it's CFrame to the torso's Position.

and you should be all set.

##BONUS TIP If you want rotation to be retained when setting the CFrame of a part, take this piece of code and modify it to your needs. The code is suited to your question, however it would serve no use since ex's rotation would be set to 0, 0, 0 already and setting CFrames has the same effect.

local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = ex.CFrame:Components() -- get the components of the CFrame of "ex".  We need this to know the rotation matrix of the part.

ex.CFrame = CFrame.new(char.Torso.Position, r00, r01, r02, r10, r11, r12, r20, r21, r22) -- Set ex's CFrame position coordinates to the position of the character's Torso, and then pop in the rotation matrix that ex possessed right before the teleport.

This discussion is preserved as it was. New answers, comments, and votes are closed.