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

Why Is My Block Spawning Above Where It Should Be?

So basically I am spawning a block and trying to check if it is touching anything. But the block is never touching anything because it always spawns above where it should, unless the spawn isn't being blocked by another block.

Here is my code:

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.G then
		
		local charge = Instance.new("Part")		
		charge.Parent = game.Workspace
		local location = game.Players.LocalPlayer.Character.Torso.Position
		charge.Position = Vector3.new (location.x, location.y, location.z + 3)
		charge.Size = Vector3.new (2, 2, 2)
		charge.Anchored = true
		wait(1)
		local touchingParts = charge:GetTouchingParts()
		charge:Destroy()
		for _, p in next, touchingParts do
			print(p.Name)
			p:Destroy()
		end
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

~~~~~~~~~~~~~~~~~.

5 comments

0

Try setting the part's CFrame instead of it's position.

0

Didn't work.

0

CFrame will ignore other parts. There's no way that would not work unless you are giving it the wrong position.

1

Set it's size then it's CFrame, when you update it's size it sets the position again

0

Thank you TheOtakuLyfe! Setting its size then it's CFrame worked!

1 answer

This question was answered in the comments I am just putting an answer down here for anyone who doesn't check the comments.

Set the part's size then set its CFrame.

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