Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Normal script
- local tweenService = game:GetService("TweenService")
- local runS = game:GetService("RunService")
- local function makePart(kind, cframe)
- cframe = cframe or CFrame.new()
- local cube = Instance.new("Part")
- local shapes = {["cube"] = Enum.PartType.Block,["sphere"] = Enum.PartType.Ball,["cylinder"] = Enum.PartType.Cylinder}
- kind = shapes[kind] ~= nil and kind or "cube"
- cube.Shape = shapes[kind]
- cube.Name = kind:gsub("^%l", string.upper)
- cube.Size = Vector3.new(4,4,4)
- local faces = {"Back","Front","Bottom","Left","Right","Top"}
- for i = 1,6 do
- local texture = Instance.new("Texture")
- texture.Texture = "http://www.roblox.com/asset/?id=4570698755"
- texture.StudsPerTileU = 2
- texture.StudsPerTileV = 2
- texture.Face = faces[i]
- texture.Parent = cube
- end
- cube.Parent = workspace.PartsFolder
- cube.CFrame = cframe
- return cube
- end
- local function doLoop(object)
- runS.Stepped:Connect(function()-- Waits for the physcis to run.
- if not object.instance then return end-- Checks if the instance of the object exists.
- if object.traveling == false then-- Checks if the object is not traveling to the past, so when is traveling, no positions are saved.
- if #object.positions > 0 then
- if object.positions[#object.positions] ~= object.instance.CFrame then
- object.positions[#object.positions+1] = object.instance.CFrame
- end
- else
- object.positions[#object.positions+1] = object.instance.CFrame
- end
- if #object.positions > object.maxPos then-- If the amount of positions in the table is greater than the max amount, then the first one gets deleted.
- table.remove(object.positions, 1)
- end
- end
- end)
- end
- local function travel(object)
- if object.traveling == false and object.instance then
- -- Setting values.
- object.traveling = true
- local oldColor = object.instance.Color
- local oldAnchored = object.instance.Anchored
- object.instance.Color = Color3.fromRGB(96, 108, 149)
- object.instance.CanCollide = false
- object.instance.Anchored = true
- -- Simple code to itherate a numerical table backwards.
- for i = #object.positions, 1, -1 do
- local v = object.positions[i]
- if v then
- local magnitude
- magnitude = (object.instance.Position - v.Position).Magnitude
- if magnitude < 1 then
- magnitude = 1
- end
- local info = TweenInfo.new(0.03 * magnitude, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0)
- local tween = tweenService:Create(object.instance, info, {CFrame = v})
- tween:Play()
- tween.Completed:Wait()
- end
- end
- object.positions = {}-- Resetting the table.
- object.instance.Color = oldColor
- object.instance.Anchored = oldAnchored
- object.instance.CanCollide = true
- object.traveling = false
- end
- end
- local class = {}
- class.__index = class
- function class.new(instance)
- if getmetatable(self) ~= nil then return warn("Attempt to perform constructor in object.") end
- if not instance then instance = makePart("cube") end
- local object = setmetatable({},class)
- object.instance = instance-- Instance of the object.
- object.positions = { }-- Table where positions are saved.
- object.maxPos = 175-- Amount of positions that can be saved, this means that if you have more positions, it will go further to the past.
- object.traveling = false-- Bool value to check if an object is "travelling" to the past.
- local tE = Instance.new("RemoteFunction")-- This is for test purposes only, if you want it to fire anotehr way, do it.
- tE.Name = "Travel"
- tE.Parent = object.instance
- tE.OnServerInvoke =function(plr, inf)
- if plr.Character and (plr.Character.HumanoidRootPart.Position-object.instance.Position).Magnitude < 25 then
- if inf == "t" then
- object:Travel()
- elseif inf == "c" then
- return object.traveling and true or false
- end
- end
- end
- object:Initialize()
- return object
- end
- function class.newEmpty(kind, cframe)
- if getmetatable(self) ~= nil then return warn("Attempt to perform constructor in object.") end
- cframe = cframe or CFrame.new(5,0,5)
- local avaible = {"cube", "sphere"}
- kind = table.find(avaible, kind) and kind or "cube"
- local instance = makePart(kind,cframe)
- class.new(instance)
- end
- function class:Initialize()
- if getmetatable(self) ~= class then return warn("Attempt to perform method in class.") end
- doLoop(self)
- end
- function class:Travel()
- if getmetatable(self) ~= class then return warn("Attempt to perform method in class.") end
- travel(self)
- end
- return class
- --Test script( used to have a more visual context )
- local tweenService = game:GetService("TweenService")
- local runS = game:GetService("RunService")
- local function createPoint(cframe)
- local point = Instance.new("Part")
- point.Size = Vector3.new(0.2,0.2,0.2)
- point.Anchored = true
- point.CanCollide = false
- point.Color = Color3.fromRGB(85, 255, 255)
- point.Material = Enum.Material.Neon
- point.CFrame = cframe
- point.Transparency = 0.5
- local mesh = Instance.new("SpecialMesh")
- mesh.MeshType = Enum.MeshType.Sphere
- mesh.Parent = point
- point.Parent = workspace
- return point
- end
- local function makePart(kind, cframe)
- cframe = cframe or CFrame.new()
- local cube = Instance.new("Part")
- local shapes = {["cube"] = Enum.PartType.Block,["sphere"] = Enum.PartType.Ball,["cylinder"] = Enum.PartType.Cylinder}
- kind = shapes[kind] ~= nil and kind or "cube"
- cube.Shape = shapes[kind]
- cube.Name = kind:gsub("^%l", string.upper)
- cube.Size = Vector3.new(4,4,4)
- local faces = {"Back","Front","Bottom","Left","Right","Top"}
- for i = 1,6 do
- local texture = Instance.new("Texture")
- texture.Texture = "http://www.roblox.com/asset/?id=4570698755"
- texture.StudsPerTileU = 2
- texture.StudsPerTileV = 2
- texture.Face = faces[i]
- texture.Parent = cube
- end
- cube.Parent = workspace.PartsFolder
- cube.CFrame = cframe
- return cube
- end
- local function doLoop(object)
- runS.Stepped:Connect(function()-- Waits for the physcis to run.
- if not object.instance then return end-- Checks if the instance of the object exists.
- if object.traveling == false then-- Checks if the object is not traveling to the past, so when is traveling, no positions are saved.
- print(#object.positions)
- if #object.positions > 0 then
- if object.positions[#object.positions] ~= object.instance.CFrame then
- object.positions[#object.positions+1] = object.instance.CFrame
- table.insert(object.points, createPoint(object.instance.CFrame))
- end
- else
- object.positions[#object.positions+1] = object.instance.CFrame
- table.insert(object.points, createPoint(object.instance.CFrame))
- end
- if #object.positions > object.maxPos then-- If the amount of positions in the table is greater than the max amount, then the first one gets deleted.
- object.points[1]:Destroy()
- table.remove(object.points, 1)
- table.remove(object.positions, 1)
- end
- end
- end)
- end
- local function travel(object)
- if object.traveling == false and object.instance then
- -- Setting values.
- object.traveling = true
- local oldColor = object.instance.Color
- local oldAnchored = object.instance.Anchored
- object.instance.Color = Color3.fromRGB(96, 108, 149)
- object.instance.CanCollide = false
- object.instance.Anchored = true
- -- Simple code to itherate a numerical table backwards.
- for i = #object.positions, 1, -1 do
- local v = object.positions[i]
- if v then
- local magnitude
- magnitude = (object.instance.Position - v.Position).Magnitude
- if magnitude < 1 then
- magnitude = 1
- end
- local info = TweenInfo.new(0.03 * magnitude, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0)
- local tween = tweenService:Create(object.instance, info, {CFrame = v})
- tween:Play()
- object.points[i]:Destroy()
- table.remove(object.points, i)
- tween.Completed:Wait()
- end
- end
- object.positions = {}-- Resetting the table.
- object.points = {}
- object.instance.Color = oldColor
- object.instance.Anchored = oldAnchored
- object.instance.CanCollide = true
- object.traveling = false
- end
- end
- local class = {}
- class.__index = class
- function class.new(instance)
- if getmetatable(self) ~= nil then return warn("Attempt to perform constructor in object.") end
- if not instance then instance = makePart("cube") end
- local object = setmetatable({},class)
- object.instance = instance-- Instance of the object.
- object.positions = { }-- Table where positions are saved.
- object.points = { }
- object.maxPos = 175-- Amount of positions that can be saved, this means that if you have more positions, it will go further to the past.
- object.traveling = false-- Bool value to check if an object is "travelling" to the past.
- local tE = Instance.new("RemoteFunction")-- This is for test purposes only, if you want it to fire anotehr way, do it.
- tE.Name = "Travel"
- tE.Parent = object.instance
- tE.OnServerInvoke =function(plr, inf)
- if plr.Character and (plr.Character.HumanoidRootPart.Position-object.instance.Position).Magnitude < 25 then
- if inf == "t" then
- object:Travel()
- elseif inf == "c" then
- return object.traveling and true or false
- end
- end
- end
- return object
- end
- function class.newEmpty(kind, cframe)
- if getmetatable(self) ~= nil then return warn("Attempt to perform constructor in object.") end
- cframe = cframe or CFrame.new(5,0,5)
- local avaible = {"cube", "sphere"}
- kind = table.find(avaible, kind) and kind or "cube"
- local instance = makePart(kind,cframe)
- class.new(instance)
- end
- function class:Initialize()
- if getmetatable(self) ~= class then return warn("Attempt to perform method in class.") end
- doLoop(self)
- end
- function class:Travel()
- if getmetatable(self) ~= class then return warn("Attempt to perform method in class.") end
- travel(self)
- end
- return class
Add Comment
Please, Sign In to add comment