#Any better way to do this?
1 messages · Page 1 of 1 (latest)
FadeVolume() seems overcomplicated I would tween a proxy and mirror the value to the Sound.Volume
Your naming for things don't seem consistent e.g. wehn to use upper characters and lower characters
I would wrap a framework like this up in a module and use that in a normal script instead of having the whole logic in a normal script
alr, thanks
Any reccomendations on the naming? like sticking to uppercase or lower?
I also don't know abt a good source for ts but these should be decent
Connection = game:GetService("RunService").Heartbeat:Connect(function()
Avoid getting services in the middle of your code, always explicitly define them at the top
Use os.clock() instead of tick() (explanation here: https://create.roblox.com/docs/reference/engine/globals/RobloxGlobals#tick)
Sound.Volume = StartVolume + (targetVolume - StartVolume) * Progress
The math library now has a lerp function: Sound.Volume = math.lerp(StartVolume, targetVolume, Progress)
Your FadeVolume function is fine, tweening a proxy instance is jank
(though I agree with zyos, that function should be a module script)
for i, player in players do
Unused variables can be replaced with _
for _, player in players do
I would not support an optional second argument in your Countdown function since the functionality becomes nearly the same as task.wait(), meaning that should be used instead
What are the differences between a normal script and a module script? what would the benefits be?
https://create.roblox.com/docs/reference/engine/classes/ModuleScript this explain what
Cool thanks.
** You are now Level 1! **
Ur welcome
Ah I get it now, so the benefit is that that function will now be usable in every script by just using require(blah blah blah) , making it so I don't have to rewrite it.
Correct
Okay so:
I've changed tick() to os.clock()
Changed Sound.Volume = StartVolume + (targetVolume - StartVolume) * Progress to Sound.Volume = math.lerp(StartVolume, targetVolume, Progress)
Put game:GetService("RunService") to happen at the start of the script
Put the FadeVolume() function into a module script.
I have added some extra code just to keep the workspace tidy as I add onto it in the future, just wondering if I've done the following correctly, as once again I'm quite new to coding and this is my first time using a module script.
For being quite new to coding your doing great
I agree
Modules scripts can return any datatype so for that module script I'd recommend doing this instead
return function(Sound, TargetVolume, Duration)
local StartVolume = Sound.Volume
local StartTime = os.clock()
local Connection
Connection = game:GetService("RunService").Heartbeat:Connect(function()
local Elapsed = os.clock() - StartTime
local Progress = math.min(Elapsed / Duration, 1)
Sound.Volume = math.lerp(StartVolume, TargetVolume, Progress)
if Progress >= 1 then
Connection:Disconnect()
end
end)
end
And to use that you would then do
local FadeVolume = require(script.Parent.FadeVolumeModule)
FadeVolume(IntermissionSound, 0.05, 5)
I'd also place FadeVolumeModule in a Util folder in ReplicatedStorage and rename the module to FadeVolume to match the function name
There are also plugins that can give you auto imports, meaning if you type out all or part of FadeVolume in any file and press tab it will automatically find the module and add a require for it to the top of your file
I've had knowledge of coding for the past 6 months, I just didn't quite know how exactly to write it all out.
Ah, okay.
Any reccomended one?>
The one I use (luau lsp) is an extension for visual studio code and not roblox studio 😭
I know there are ones that exist for studio because I've seen them, I just don't know their names sorry
Alright all good, I'm sure I'll be able to find one.
What exactly is a Util folder, and what is the purpose of putting FadeVolumeModule in a Util folder in ReplicatedStorage?
Completely subjective organization
(util folder is just a folder named Util, short for Utility)
alr
*putting it in replicated storage does serve a purpose though. Stuff in replicated storage is replicated to each client when they join, meaning code and assets that are inside of it can be accessed from local scripts
also another thing, theres 100% a better way to do this right? local FadeModule = require(script.Parent.Parent.ReplicatedStorage.Util.FadeVolume) I'm certain there is but im not sure what it is
** You are now Level 2! **
oh yeah
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FadeModule = require(ReplicatedStorage.Util.FadeVolume)
cool, thanks for helping out
Hey I'm not sure if you know much about coding with GUI, but I've been wanting to make the current Countdown() from my RoundScript be displayed through GUI, as right now it only prints within console.
^ what i've got rn
I'm not sure specifically what you need help with here
Generally a simple solution would be a remote event that the client listens to and updates the text to any message it revives
Then from the server you can fire the event from anywhere to update the text
oh alrighty
ive never quite touched remote events, not quite sure how to use them in code
Have you used normal events? (like with :Connect)
Set up by adding a RemoteEvent called UpdateText to ReplicatedStorage/Events
A local script
local event = ReplicatedStorage.Events.UpdateText
event.OnClientEvent:Connect(function(msg)
print(`Got "{msg}" from server`)
end)
A server script
local event = ReplicatedStorage.Events.UpdateText
event:FireAllClients("Hello, World!")
You could extend that by calling event:FireAllClients("Hello, World!") each time you loop in Cooldown and to set messages like event:FireAllClients("Waiting for players...")
On the client instead of printing you can place the script inside the UI and easily reference the text label to update its text
-# In the future if/when you start to notice that doing stuff that way gets difficult to maintain in large projects, check out Fusion & UILabs. They are much more advanced ways of making UI and share some similarities with modern web development frameworks. They have a lot of advantages with UI reusaiblity and modularity, but I'm not sure if I would recommend learning all of that now though because its a lot to learn and you realistically don't need it when just starting out. There are also networking libraries like Blink that handle argument validation and can reduce network load. Again I wouldn't recommend learning those now just kinda a thing to keep in mind for later (I'm glad I didn't immediately start doing that stuff but I wish I found out about it sooner so thats why I'm putting this huge wall of text here). Also theres Rojo which lets you use version control like git and other external tooling
1 time for the script I had above, never before.