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

How to do a local variable for CFrame?

Asked by 6 years ago

Hey there! I have a question! So I am making a game with water that rises but how can I make the script below more efficient? I want to so I do not have to type out every single line for each time the water goes up and instead have it like:

while true do
local time = 5
height = +5
local cframe = (-272,height,122.5)

terrain=workspace.Terrain
cframe=CFrame.new(-272, -25.995, 122.5)
size=Vector3.new(2029, 21, 1907)

But I know that that wouldn't work so how can I do it so that the water spawns on the Y axis every 5 seconds by doing +5 to only the Y cframe? Below is my inefficient script!

local time = 5


terrain=workspace.Terrain
cframe=CFrame.new(-272, -25.995, 122.5)
size=Vector3.new(2029, 21, 1907)

terrain:FillBlock(cframe,size,Enum.Material.Water)

wait(time)
terrain=workspace.Terrain
cframe1=CFrame.new(-272, -13.995, 122.5)
size1=Vector3.new(2029, 21, 1907)

terrain:FillBlock(cframe1,size1,Enum.Material.Water)

wait(time)
terrain=workspace.Terrain
cframe1=CFrame.new(-272, -8.995, 122.5)
size1=Vector3.new(2029, 21, 1907)

terrain:FillBlock(cframe1,size1,Enum.Material.Water)

wait(time)
terrain=workspace.Terrain
cframe1=CFrame.new(-272, -0.495, 122.5)
size1=Vector3.new(2029, 21, 1907)

terrain:FillBlock(cframe1,size1,Enum.Material.Water)

wait(time)
terrain=workspace.Terrain
cframe1=CFrame.new(-272, 8.005, 122.5)
size1=Vector3.new(2029, 21, 1907)

terrain:FillBlock(cframe1,size1,Enum.Material.Water)
0
Your first code is literally nothing, it should not work because it will either hang or because their is no "end", it won't work greatneil80 2647 — 6y
0
I made that off of the top of my mind of an example of what I wanted to know how to do. But thank you for your concern. BunnyFilms1 297 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

It must be height = height + 5, since height = +5 is undefined on what number you're adding 5 to.

You can also just do while wait(time) do to make it go every 5 seconds.

The following code below should do the trick.

local time = 5
local terrain = workspace.Terrain
local height = 0

while wait(time) do
height = height + 5
cframe=CFrame.new(-272, -25.995+height, 122.5)
size=Vector3.new(2029, 21, 1907)
terrain:FillBlock(cframe,size,Enum.Material.Water)
end

~SkeletalReality

Ad

Answer this question