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

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

Asked by
hoth7 45
4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

0
12:28:16.918 - ServerScriptService.Meteor:3: attempt to compare Vector3 hoth7 45 — 4y
0
You can’t compare Vector3’s using <=, <, >, or >= because Roblox doesn’t implement __lt nor __le metamethods. VitroxVox 884 — 4y
0
Oh right, I totally forgot about that. Let me edit my answer. Sorry! DevMaster333 215 — 4y
0
Fixed it, forgot to add magnitude. It should work now. :) DevMaster333 215 — 4y
View all comments (7 more)
0
Didn't work hoth7 45 — 4y
0
Did you define the variable "part" to the part you're looking for? DevMaster333 215 — 4y
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 DevMaster333 215 — 4y
0
Didn't work still hoth7 45 — 4y
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. DevMaster333 215 — 4y
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. DevMaster333 215 — 4y
0
Any updates on how it went? DevMaster333 215 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question