You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A function where the lava spinner (sweeper) gradually increases as time passes.
What is the issue? Include screenshots / videos if possible!
I’m currently working on a prototype minigame, called the Lava Spinner, currently It’s controlled manually to where I can press a button to start the spinner, and one which ends it, however I’d like to make it so that the spinner starts slow and gradually increases as time passes.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve spent over 10 hours so far, setting variables, renaming objects, rescripting but nothing seemed to work, it’d be greatly appreciated if someone could guide me step by step as what I am supposed to do or come in studio and take a look at the code, I used to script Lua a few years back, however I’ve mostly forgotten how to script in basic Lua form. I’m more professional at HTML, JS and Python.
ATTACHED IS AN OPEN-SOURCED GAME OF THE SPINNER:
If anyone can help me out, or give me very very basic instructions as how it could work, that’ll be greatly appreciated! (The game works if it is saved as a model too)
This is really neat! Do you think you could tell me how to implement this later? Here is the current code I have:
SPIN (on it’s own)
while true do
spinning.CFrame = spinning.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(10.5), 0)
wait(0.00)
end
BUTTON PRESS (DISABLE/STOP)
for _,Obj in pairs(workspace["The Sweeper"]:GetChildren()) do
if Obj:IsA("BasePart") then
OriginalCFrames[Obj] = Obj.CFrame
end
end
function onClick(click)
script.Parent.Parent.BrickColor = BrickColor.new("Really red")
workspace["The Sweeper"].Sweeper.Spin.Disabled = true
for Block,CF in pairs(OriginalCFrames) do
Block.CFrame = CF
end
end
script.Parent.MouseClick:connect(onClick)
ENABLED/START
for _,Obj in pairs(workspace["The Sweeper"]:GetChildren()) do
if Obj:IsA("BasePart") then
OriginalCFrames[Obj] = Obj.CFrame
end
end
function onClick(click)
script.Parent.Parent.BrickColor = BrickColor.new("Really red")
workspace["The Sweeper"].Sweeper.Spin.Disabled = false
for Block,CF in pairs(OriginalCFrames) do
Block.CFrame = CF
end
end
script.Parent.MouseClick:connect(onClick)
local StartAngle = 10.5
local PercentageIncrement = (INSERT NUMBER 1 TO 100)
local LastTime = 0 – being the amount of time passed
while true do
– the exponential equation to increase over time
local NewAngle = StartAngle * (1 + (PercentageIncrement/100))^LastTime
spinning.CFrame = spinning.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(NewAngle), 0)
wait ()
LastTime = LastTime + 0.01 – time passed, idk if this is right
end
What I would do is use TweenService and the EasingStyle called Sine. What you can do is when a button is pressed you Tweenit to spin and gradually grow and you can stop the tween as soon as you press the other button. For more information check on the Developer Hub.
Here there, I’ve heard of TweenService before, however my scripting is very basic and in all honesty, I really don’t understand what the first step would be when it comes to using Tween Service, do you think you could direct me with how the code would work with the open-source code I posted above? It’d really help and be a good learning experience for me.
This is incredibly simple. Have a hinge constraint set as a motor moving the spinner, and have this code run in your game in a server script:
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(Time)--the number of seconds you want it to take to reach maximum speed
local Goals = {AngularSpeed = Speed}--change "speed" with the speed you want it to go at
local Tween = TweenService:Create(Spinner,Info,Goals)
Tween:Play()
What this will do is smoothly interpolate (change) the spinner’s speed without you having to mess with anything!
Hey everyone, quick update, I still haven’t solved the problem yet, however a friend suggested the following code to replace the “spin” script in.
local Degrees = 1 -- How much it starts out with
game:GetService("RunService").Heartbeat:Connect(function()
if Degrees < 6 then
Degrees = Degrees + 0.01
end
Spinner.CFrame = Spinner.CFrame * CFrame.Angles(0,math.rad(Degrees),0)
end
I tried plugging it in, however It didn’t seem to work, I asked him about it and he really didn’t know either, can anyone review this? Is this right compared to the open-source code posted above? Or Is this totally wrong? I’ve been stuck on this for a few days now sadly ):
Doesn’t seem to work how? Details need to be provided here so we can help you. Be sure to also apply basic debugging to your code before posting, since a lot of issues can be resolved through spending a bit of time reviewing your code.