Hey, I’ve seen some posts about this topic, but none of them actually helps me.
Basically what i want to achieve is something like a pulse using particles that happens every hour starting at (as an example) 2 PM et on April 22 until April 26, and using os.time of course.
Is there any way to do that? I’m really not that professional at scripting, but i’m trying my best trying to understand everything.
If you could help me I would really appreciate your help
local interval = 3600 -- 1 hour in seconds
local event = Instance.new("BindableEvent")
local function onHourPassed()
-- Code for the event happening every hour goes here
print("Event happening every hour!")
end
event.Event:Connect(onHourPassed)
while true do
wait(interval)
event:Fire()
end
You can place this script in a ServerScriptService in Roblox Studio. This script creates a BindableEvent and connects a function onHourPassed to it. The script then enters a loop where it waits for the specified interval (1 hour in this case) and then fires the event. The onHourPassed function is called every time the event is fired, achieving the event happening every hour.
Apologies for missing that part. Here’s an updated Roblox Studio script in Lua that uses os.time() to achieve an event happening every hour:
local Pulse = script.Parent -- Reference to the object where the particles will be emitted
local interval = 3600 -- 1 hour in seconds
local startTime = os.time({year = 2022, month = 4, day = 22, hour = 14, min = 0, sec = 0}) -- Start time (2 PM on April 22, 2022)
local endTime = os.time({year = 2022, month = 4, day = 26, hour = 0, min = 0, sec = 0}) -- End time (Midnight on April 26, 2022)
while true do
wait(1) -- Wait 1 second before checking the time again
local currentTime = os.time()
if currentTime >= startTime and currentTime < endTime and (currentTime - startTime) % interval == 0 then
-- Create the pulse effect with particles here
local particle = Instance.new("ParticleEmitter")
particle.Parent = Pulse
-- Set particle properties (e.g., texture, speed, size, color)
wait(10) -- Wait for 10 seconds before removing the particles
particle:Destroy()
end
end
In this script, the Pulse variable should be set to the object in your game where you want the particle effect to be emitted. The script will check the current time every second and create the pulse effect with particles every hour between the designated start and end times.
Please note that you may need to adjust the properties and settings of the ParticleEmitter to achieve the desired visual effect. I hope this helps!
Did he use an AI? If that’s so, ¿What’s the deal? He really helped me, i get some of you hate ai because of certain things, BUT, look closely at the post, it’s been almost 4 days, no dev replied, and the only one who did was that guy (who actually helped me a lot).
So even if he used AI he helped me understand some things i didn’t, so i’m grateful for that.
Well, for starters, you shouldn’t use whilte true do loops because it’s a code smell, you should use task.wait() instead of wait(), and should use DateTime objects for this instead of os.time() since they’re far superior. The AI of course doesn’t know this, and the user posting the AI generated response is both unwittingly sharing bad code and grossly passing off an AI generated response as though it’s their own knowledge.
DateTime objects will allow you to account for time zones and easily format how much time is remaining until the next event for displaying to users. It also has a better documentation and a better, clearer, easier to use API.
For example, DateTime.now():ToUniversalTime().Hour will give you the current hour in the day without having to format a timestamp.
I honestly use AI all the time. I don’t get why people hate AI so much, it has legit helped with so many things (as well as asking the dev forum of course). I think it’s because that whoever uses AI has either a basic or no understanding of the code at all, and they just write off bad code as their own or think it will work when it doesn’t.
I think when you’re of intermediate coding, you can use AI for scripting challenges or ideas and you can notice which thing is wrong, and being intermediate, code that little part of the code yourself with little to no effort.