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

player.Character:GetExtentsSize() doesn't return the offset used from the head?

I'm making a script where you can freeze other players. The players have morphs as well, which are stored inside of the player's character. This means that :GetExtentsSize() gets the correct size of the entire player model, but it doesn't return the offset used to make it. According to the wiki, it uses an offset based on a primary part (in this case, the player's head). How can I get it to position the block of ice correctly?

local iceblock = Instance.new("Part")
iceblock.Anchored = true
iceblock.Transparency = 0.5
iceblock.BrickColor = BrickColor.new("Teal")

--This fires when the player is hit and becomes frozen:
plr.Character.Torso.Anchored = true
local newice = iceblock:clone()
newice.Size = plr.Character:GetExtentsSize()
newice.CFrame = plr.Character:GetPrimaryPartCFrame()
newice.Parent = game.Workspace
repeat
wait(5)
until math.random(1,5) == 1
newice:Destroy()
plr.Character.Torso.Anchored = false

1 comment

0

Note that I only gave excerpts from the main script, because that's where the problem lies.

1 answer

✓ Accepted answer

Hmm, seems the wiki was wrong about that. I'll take a look into that and fix it, but I'm curious what the previous writer meant by having a vector3 that represents size be aligned to a position. That doesn't seem possible to me given all that's returned is a size vector 3????

Anyways...

For your purposes I'm going to recommend a depreciated method which I hate to do, but realistically I don't think it should be depreciated if it's the easiest thing to use in a situation.

http://wiki.roblox.com/index.php?title=API:Class/Model/GetModelCFrame

That will give you the dead centre of the object that you need. So for example, in use:

local iceblock = Instance.new("Part");
iceblock.Anchored = true;
iceblock.Transparency = 0.5;
iceblock.BrickColor = BrickColor.new("Teal");

script.Parent.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid");
	local plr = hum and game.Players:GetPlayerFromCharacter(hum.Parent);
	if plr then
		--This fires when the player is hit and becomes frozen:
		plr.Character.Torso.Anchored = true;
		
		local newice = iceblock:Clone();
		newice.Size = plr.Character:GetExtentsSize();
		newice.CFrame = plr.Character:GetModelCFrame();
		newice.Parent = game.Workspace;
		
		repeat
		wait(5);
		until math.random(1,5) == 1;
		
		newice:Destroy();
		plr.Character.Torso.Anchored = false;
	end;	
end);

1 comment

0

It worked! Thanks!

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