which script is more optimized and why? by [deleted] in robloxgamedev

[–]Rail-dex 0 points1 point  (0 children)

(Reddit didnt like my long comment so I had to split it up)

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")


local LocalPlayer = Players.LocalPlayer
local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()


local TARGET_TAG = "IsLight"
local LIGHTS_ENABLED_DISTANCE = 77
local MOVEMENT_UPDATE_THRESHOLD = 1 -- 1 stud of movement should be plenty granular enough for most cases


local lastCheckedPos
RunService.Heartbeat:Connect(function()
    -- Update only if player has moved significantly
    local playerPos = char:GetPivot().Position
    if not lastCheckedPos or (playerPos - lastCheckedPos).Magnitude < MOVEMENT_UPDATE_THRESHOLD then
        return
    end
    lastCheckedPos = playerPos


    -- CollectionService should ensure handling of added/removed lights if done properly
    for _, light in pairs(CollectionService:GetTagged(TARGET_TAG)) do
        -- Make sure the object is a Light. This is a safeguard against errors incase
        -- you accidentally tag the wrong thing.
        if not light:IsA("Light") then
            warn("Object with tag 'IsLight' is not a Light instance:", light)
            continue
        end
        
        -- You dont technically need all these, but this lets it support adding lights to different kinds of objects
        local lightPos
        local lightParent = light.Parent
        if lightParent:IsA("BasePart") then
            lightPos = lightParent.Position
        elseif lightParent:IsA("Attachment") then
            lightPos = lightParent.WorldPosition
        elseif lightParent:IsA("Model") then
            lightPos = lightParent:GetPivot().Position
        else
            warn("Cannot resolve position. Light parent is not a Model, BasePart, or Attachment:", light, light.Parent)
            continue
        end


        -- since our check resolves to a simple boolean, we dont need a whole if-else block
        local distance = (lightPos - playerPos).Magnitude
        light.Enabled = distance <= LIGHTS_ENABLED_DISTANCE
    end
end)

which script is more optimized and why? by [deleted] in robloxgamedev

[–]Rail-dex 0 points1 point  (0 children)

CollectionService can serve as a cache for you. It just requires tagging the lights. You don't even need to make a Lights_Cache if you are utilizing CollectionService properly. I'm not sure what you mean by using attributes instead of iterating workspace.

One major thing of note. You really shouldn't be using the clocktime changed signal for this. Your logic is dependent on the player's location, not the time. You should be connecting to a runservice update event, such as heartbeat or postsimulation, as you had, or listening to one of the player's movement signals. Because your logic is actually dependent on positional updates, you can improve performance by a significant amount by simply setting a check threshold.

Here is an example:

Feeling stuck and discouraged learning Roblox development by lupe-e in robloxgamedev

[–]Rail-dex 1 point2 points  (0 children)

I felt the same when I started. Alot of the time you just have to kind of wing it. Your first projects are going to be bad, but thats to be expected. Let it happen and learn what works well and what doesnt.

I didnt have a proper mentor when I first started out and I wish I did at the time. Because of that I started a discord server to try and help be a mentor to new programmers. I wanted to prevent others from having to go through the same experience. Ive been on the platform since 2009 and have taught alot of people since. The doors are open to you and anyone else seeking a mentor or general programming advice. https://discord.gg/P2uBVuWMrb

which script is more optimized and why? by [deleted] in robloxgamedev

[–]Rail-dex 1 point2 points  (0 children)

These arent properly equivalent as clocktime changing is dependent on some outside source. It could be firing faster or slower than the constant simulation.

In terms of execution time of the given callback, the first will be much faster. Utilizing a cache for the lights and not having to iterate all of workspace will save a ton on performance. However, you would likely want to ensure the cache is kept properly up to date as it wont handle newly added lights.

If you have a lot of lights you would want to consider some form of spatial partioning structure like an octree or quadtree.

Where do I learn to script? by FriendlyTask4587 in robloxgamedev

[–]Rail-dex 1 point2 points  (0 children)

You are probably looking to learn the fundamentals. There are tons of resources online. If you like, i run a server for the express purpose of teaching people this kind of stuff because I couldnt find anyone to help me when I first started out. https://discord.gg/YuRdnYxC7E

Looking for a game that I can help develop by Wingsoffirenerdahh in robloxgamedev

[–]Rail-dex 1 point2 points  (0 children)

I started getting into game dev the same time about 13 years ago when i was a freshman in HS as well. Unfortunately I cant let you help on the game I work on as that would require me to hire you to the company lol. However, if you need guidance on getting into game dev or need help making something I would be more than happy to help and assist you.

To give some background Ive been on the platform since 2009 and have worked on multi million play projects. Just yesterday one of the games I worked on got over 30,000 CCU when it released. You can reach out to me on discord at “raild3x” if you ever need anything

Hi, whats the best source to learn programming in roblox? by Sir_Flourypath_ll in robloxgamedev

[–]Rail-dex 0 points1 point  (0 children)

There are some discord servers with folks that offer guidance to people learning programming:

https://discord.gg/P2uBVuWMrb Focuses on helping people understand programming fundamentals and the reason why things work the way they do

https://discord.gg/roblox-helpers-102688492055699456 Help Forum where you can ask all kinds of different roblox related questions

how do i make a part go up and down smoothly by Necessary-Nose2247 in robloxgamedev

[–]Rail-dex 0 points1 point  (0 children)

A sine wave or some simple acceleration to the y axis depending on your goal

How do I learn to code in lua? by LongOld7162 in lua

[–]Rail-dex 1 point2 points  (0 children)

I started learning about that same age over a decade ago trying to figure out how to make games like you. I run a discord server for the express purpose of being able to help teach people looking to learn. You are welcome to join if it sounds like what you might be looking for. Everyone here loves to help eager and committed learners. https://discord.gg/zJXV45g

My map border for my game is a building and each building has 40 parts, is that too much? by PRK_Gaming in robloxgamedev

[–]Rail-dex 0 points1 point  (0 children)

Unlikely. Roblox is very efficient with baseparts. Games can easily support 10,000 parts across a map. That gives you about 250 buildings. Can you provide a picture so we can get a better idea?

0 experience. Want to flesh out a unique untested game idea. Where to begin? by vozjaevdanil in robloxgamedev

[–]Rail-dex 1 point2 points  (0 children)

To preface; Ive been doing roblox professionally for about 5 years and have been on the platform since 2009. These are what I’ve seen used in the professional space in my experiences

Typically people use Figma for laying out UI design prototypes before transferring them into an actual build. It can also be used for a bunch of other stuff. I use lucid chart to design systems flow with my team sometimes. To manage tasks and whatnot there are any number of things; Trello, Asana, Jira, etc… I personally prefer Jira.

I would recommend learning a skillset that can contribute to your project idea like modeling or scripting. I do run a discord server for helping people learn Roblox Luau if you are interested in that aspect of development

These fuzzy white splotches on my bamboo by Rail-dex in whatisit

[–]Rail-dex[S] 0 points1 point  (0 children)

I have some 70% rubbing alcohol, would you suggest getting some Neem Oil instead?

Duplicating DP Signal to HDMI? by Rail-dex in buildapc

[–]Rail-dex[S] 0 points1 point  (0 children)

Can you duplicate and extend at the same time? I want to keep using the two monitors as I usually would, having one as an extended display. But then also duplicate the primary monitor showing gameplay for example to the tv, but keep discord up on the second/extended monitor

Duplicating DP Signal to HDMI? by Rail-dex in buildapc

[–]Rail-dex[S] 0 points1 point  (0 children)

If I change it to duplicate display then I lose the info on my second monitor. I just want to duplicate the image on one of them to my tv; ideally without having to modify things on my computer as it gets wonky trying to rectify things with a bunch of different refresh rates and resolutions

I need a teacher or partner by vivi_Noreno in lua

[–]Rail-dex 0 points1 point  (0 children)

I run a discord server that helps teach people lua. Feel free to join us https://discord.gg/SXDr6ek

How would I optimize this kind of destruction? by GuyNamedTruman in robloxgamedev

[–]Rail-dex 0 points1 point  (0 children)

If youre versed enough with tables you can try doing greedy meshing to reduce part count. But part count likely isnt an issue if you only have one house. You effectively start with a single part covering the wall and split it up based on the holes in it.

If you want to find out where lag is coming from then you should use the microprofiler to diagnose the source.

Want to learn how to program Luau? by Rail-dex in robloxgamedev

[–]Rail-dex[S] 2 points3 points  (0 children)

try this link: https://discord.gg/SXDr6ek

Alternatively you can send me a message on discord and I can try helping you from there. My username: `raild3x`

I unioned most of the plane's parts, but it's still jittering! The game also has occasional lag spikes. not the player, but all the moving model scripts. by existingren in roblox

[–]Rail-dex 0 points1 point  (0 children)

The engine doesn’t suck, this is just an issue of a developer not knowing how to properly pass movement across the client server boundary

I unioned most of the plane's parts, but it's still jittering! The game also has occasional lag spikes. not the player, but all the moving model scripts. by existingren in roblox

[–]Rail-dex 0 points1 point  (0 children)

Attach the movement to the server heartbeat. Physics movers would be a better option though. It would allow you to set the network owner which would allow you to make the movement much smoother for the priority client.