Skip to content

Instantly share code, notes, and snippets.

@davegurnell
Last active April 16, 2022 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davegurnell/ada80344968a895b6af26e84587de076 to your computer and use it in GitHub Desktop.
Save davegurnell/ada80344968a895b6af26e84587de076 to your computer and use it in GitHub Desktop.
points = script.Parent
--[[
This script creates 100 cubes representing "points" on a graph.
It loops through the values of x from 0 to 100, and calculates the correct y value at each position.
For each pair of values, it creates a cube at position x,y.
]]
-- Create a variable called "x" and set it to 0
x = 0
-- Keep running the block of code below over and over again until x is 100.
-- When x is 100, carry on from below the block.
while x < 100 do
-- Calculate the correct value of y for the current value of x:
y = x + 10
-- Create a cube at x,y
point = Instance.new("Part", points)
point.Anchored = true
point.Size = Vector3.new(1,1,1)
point.Position = Vector3.new(x, y, 0)
-- Increase the value of x by 1 and loop back to line 14.
x = x + 1
end
println("Finished!")
--[[
A variant of the first example that moves the spawn location
instead of creating new parts.
]]
-- Create a variable called "platform" and use it to refer to the spawn location.
-- This assumes that the spawn in your workspace is called "SpawnLocation".
platform = workspace:FindFirstChild("SpawnLocation")
x = 0
while x < 100 do
y = x + 10
-- Set the position of the "platform" (i.e. the spawn location).
-- Note that the player won't move automatically with the platform,
-- although they can use WASD to walk along above it.
platform.Position = Vector3.new(x, y, 0)
x = x + 1
-- Wait for 1 second before looping.
-- This is quite a long delay and creates a "blocky" animation.
-- If we shorten the delay to something like 0.1 seconds,
-- the animation will look smoother but the platform will move faster!
-- If we change "x = x + 1" to a smaller increment like "x = x + 0.1",
-- the movement will slow down again to compensate for the faster loop speed.
wait(1);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment