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

Can't get text to change when part size is changed?

So currently I'm trying to make it so whenever the size of the part is 2,2,2 it changes the text to "Meteor" however, it is not working. Please help!

if game.Workspace.Sizedparttest.Size == ("2,2,2") then
	game.Players.LocalPlayer.PlayerGui.size.Frame.Textlabel.Text = "Meteor"
end

2 answers

Size is a vector 3 and so you must create a vector 3 when you're trying to compare it. Also, you want to always use higher or equal since the size might not be exactly the size you're trying to compare it to. Finally, since you can't right out compare vector3 you want to add magnitude so you compare the length of the vector. Here's how you would do it:

local part = game.Workspace:FindFirstChild("Part")

if part.Size.Magnitude >= Vector3.new(2,2,2).Magnitude then
	game.Players.LocalPlayer.PlayerGui.size.Frame.Textlabel.Text = "Meteor"
end

Let me know how it goes!

11 comments

0

12:28:16.918 - ServerScriptService.Meteor:3: attempt to compare Vector3

0

You can’t compare Vector3’s using <=, <, >, or >= because Roblox doesn’t implement __lt nor __le metamethods.

0

Oh right, I totally forgot about that. Let me edit my answer. Sorry!

0

Fixed it, forgot to add magnitude. It should work now. :)

0

Didn't work

0

Did you define the variable "part" to the part you're looking for?

0

Make sure the part has a unique name so it doesn't find another part. You could also simply put the script under the part in workspace then define part with part = script.Parent

0

Didn't work still

0

What is wrong? It is working fine for me. Can you show your whole script so I can check if you're doing it right.

0

Put a Print("Part is bigger") just to confirm that it does detect that the part is bigger. If the text is not changing, then maybe you're not calling it properly.

0

Any updates on how it went?

This should work:

if game.Workspace.Sizedparttest.Size.X == 2 and game.Workspace.Sizedparttest.Size.Y== 2 and game.Workspace.Sizedparttest.Size.Z == 2 then
	game.Players.LocalPlayer.PlayerGui.size.Frame.Textlabel.Text = "Meteor"
end

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