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

How to use Vector3?

Asked by 10 years ago

I want to make a part that spreads when you touch it, but it wouldnt work. What I have so far :

function onTouch(hit)
         script.Parent.CFrame.Vector3(5,1,6)
         wait(10)
end

0
What do you mean by "spreads"? BlueTaslem 18071 — 10y
0
Make the Size bigger? Thetacah 712 — 10y

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Size is just a regular property of Parts, just like Transparency or BrickColor.

When we set Transparency, it looks like this:

script.Parent.Transparency = 0.5

So when we change Size, it should look the same:

script.Parent.Size = ...

However, a Size isn't a number like Transparency is. It's a Vector3


To make a new Vector3 value we use the constructor Vector3.new(x,y,z)

We can also operator on Vector3s in a way very similar to numbers to produce new ones. Just like we can use Transparency + 0.1, we can also add to Vector3s:

script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1)
-- Increases the X, Y, and Z components by 1 stud

If you're doing this with a Touched event, you'll probably want to add some sort of debounce system to prevent problems from the part repeatedly getting touched because it's getting larger:

wasTouchedLastSecond = false

function onTouch()
    if not wasTouchedLastSecond then
        wasTouchedLastSecond = true
        script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1)
        wait(1)
        wasTouchedLastSecond = false
    end
end
Ad

Answer this question