Creating a part to encase the player

local freezePart = Instance.new('Part', character)
freezePart.Name = 'Freeze'
freezePart.Anchored = true
freezePart.Size = Vector3.new(5, 5.5, 4)
freezePart.Position = character:FindFirstChild('HumanoidRootPart').Position

I’m trying to create a part when a player gets touched by another player. He’s the section of code that creates the part. It creates the part, but the part gets placed on top of the characters head. I want the part to basically ‘trap’ the player (basically how TwoShue’s freeze tag game used to work) so the player gets trapped in like a block of ice.

So kinda how this looks

The part where the player actually gets trapped is done simply by anchoring their character so it cannot move at all (e.g. Character.HumanoidRootPart.Anchored = true).

The freeze parts are just visual and may also be used as the hitbox for thawing a player.

Also, just some tips:

  • Set the CFrame of freezePart, not the position, otherwise it may just go on top of the character (Roblox clipping stuff, not sure what state it is in rn).
  • Disable CanCollide on freezePart so the character won’t glitch out of the part when it gets created, and so their camera and stuff can leave the part too
1 Like
freezePart.CFrame = character:FindFirstChild('HumanoidRootPart').Position

I did this and it just put it in like the centre of the game? I’m guessing 0,0,0

1 Like

Try:

freezePart.CFrame = CFrame.new(character:FindFirstChild(‘HumanoidRootPart’).Position)

This creates a new CFrame and uses the rootpart’s Vector3 values.
TIP: Always look up what data type you need to use when setting a property.
http://wiki.roblox.com/index.php?title=CFrame

2 Likes

Side note, setting the parent of the part after all modifications to it’s properties are made is slightly better from a performance perspective.

5 Likes
local freezePart = Instance.new('Part')
freezePart.Name = 'Freeze'
freezePart.Anchored = true
freezePart.Size = Vector3.new(5, 5.5, 4)
freezePart.CFrame = character:FindFirstChild('HumanoidRootPart').CFrame
freezePart.Parent = character
1 Like

I would be using CFrame for your case rather than trying to use a Vector3 (from the character’s torso’s position).

The difference between Vector3 and CFrame is that Vector3 forces some sort of collision detection on your system. CFrame on the other hand uses a completely separate method that is more reliant 3D space of the game rather than applying some sort of collision system.
You can read up more over here: http://wiki.roblox.com/index.php?title=CFrame

The solution is simple, just replace the line where you assign the position:

freezePart.Position = character:FindFirstChild(‘HumanoidRootPart’).Position

And replace it with:

freezePart.CFrame = character:FindFirstChild(‘HumanoidRootPart’).CFrame

Side note that there’s no point using FindFirstChild if you are indexing the return value without checking that it isn’t nil first.

4 Likes

Eh, I can see it being used sometimes. In this case it’s pointless.

Yup, if FindFirstChild() returns nil, you are still calling .CFrame and you will still get an error. I’d recommend either checking to make sure the result isn’t nil (before you even create the freeze part).