Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Is My Block Spawning Above Where It Should Be?

Asked by 6 years ago

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)

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

0
Try setting the part's CFrame instead of it's position. call23re2 87 — 6y
0
Didn't work. JetAviz 0 — 6y
0
CFrame will ignore other parts. There's no way that would not work unless you are giving it the wrong position. lukeb50 631 — 6y
1
Set it's size then it's CFrame, when you update it's size it sets the position again xEmmalyx 285 — 6y
0
Thank you TheOtakuLyfe! Setting its size then it's CFrame worked! JetAviz 0 — 6y

1 answer

Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
6 years ago

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.

Ad

Answer this question