How to caculate 'Wall studs' and their positions

Hey developers. I want to make a private plugin for our builder developers to use so they can enjoy quickly building, without it being a pain. So far, the plug-in part is working great, however the ‘roblox scripting is not’ lol.

Basicially our poor builders are having to mannually add each wall stud like below:

Basicially what I want to do is have it so, the part you select in the plugin, automaticly adds the wall studs. You see, All walls have this middle, where the wall stud rests in the middle of. The wall stud should have the same size as this middle piece (Ex. in length inside the wall. Pretend the picture above has a double sided wall. where the wall studs need to be showing on both sides of the wall in that axis.), however thickness and height are customizable. Now I’m not asking for you to make this for me.

What I am asking is this. How can I make it so the wall studs show up from left to right, especially when the middle piece can be in different orientations. Could you possibly provide an example in a code block, of a wall needing 5 ‘wall studs’ (I’m a visual person and so this was very hard for me to think of, bc I don’t know CFrames well). And/Or any Roblox doc., videos that can help!

Any and all help is much appreciated! (I’m just trying to help my other developers but this is taking a lot of time :frowning: )

2 Likes

I don’t know much about this specific subject, but I believe for the middle you can probably use the pivot of the wall/model, and to do it on both sides maybe use a for loop for the amount of wall studs?

local wallstudamount = X
local cframe = selection.middle.CFrame (also not how you access it, just giving a general idea)

for i = 1, wallstudamount do
    local studLeft =  (create a stud)
    local studRight = (create a stud)

    studLeft.Position = cframe * CFrame.new()
    studRight.Position = cframe * CFrame.new() -- might be able to * this by i to account for offset
-- increase the cframe to the next position where it's needed then loop
end

To determine both cframe positions you may have to do calculations based on the size of said part. One of the positions will be negative (maybe * i) to spawn it on the opposite side. also i never tested any of this and it might be *= instead of * or something like that, i’m inexperienced when it comes to this subject. sorry i’m so horrible at explaining this as well, I’ve never really worked with stuff like this before, i’m just giving a general idea

4 Likes

I have gone ahead and made a test place to really just see what I can do. I took your script and did some changes (In this test, the script was located inside the ‘test middle line part’)

local wallstudamount = 10
local cframe = script.Parent.CFrame


			for i = 1, wallstudamount do
				local OneStud =  game.Workspace.TesterStud:Clone()
	
	
	OneStud.Parent = workspace
OneStud.Size = Vector3.new(OneStud.Size.X, OneStud.Size.Y, script.Parent.Size.Z)
	OneStud.CFrame = cframe * CFrame.new() * CFrame.Angles(0, 0, math.rad(90))
				

end

Now this works in the fact, that it is able to generate as many parts I need and put them at the middle of middle line straight up! However I guess I do have to ask an embarrassing which I feel dumb for asking but uh… How does one caculate this offset. Because yes, the size of the middle part changes. So How can I get the mini. and max, position of this line in the part if that makes sense? and how can I space them as needed.


Again though, this is somewhere to start so thank you so much already! and I’m still testing stuff around

2 Likes

Thanks! I never even thought this would work. For the offset, you might be able to multiply the clipping wall stud by the iterator (i) which will give you the amount of times it looped. I don’t fully know if this might work but hopefully it does I meant this to calculate the wall studs in the opposite direction, ignore this

Now I have no clue, but you’d need to calculate the offset based on the size of something, for example, Onestud’s X size * Offset, which I have no idea how you’d go about it but there’s a baseline to start.

I made a stomp ability that spawned 3 hitboxes before and this is how I offset it. (the functions don’t matter)
The size of the hitbox is 30, 50, 30 so I offset it by -30 to spawn right in front of the last hitbox, to make it spawn slightly in front of the last hitbox i think you’d multiply it by the offset so

for i = 1,3 do
	local hitEnemies = {}
	spawnHitBox(cframe, Vector3.new(30, 50, 30), hitEnemies)
	playStompSound()
	cframe *= CFrame.new(0,0,-30) -- MULTIPLY THIS BY THE OFFSET TO DETERMINE HOW FAR IN FRONT IT IS
	task.wait(.25)
end

Also, if you’re making a plugin you should allow the user to input the offset so they can make multiple. TELL ME IF IT WORKED, ID LOVE TO USE THIS PLUGIN LOL

2 Likes

Well so yes, I want to have both. I want it so a computes a result based on amount of parts as an auto amount. Ex. If there is 2 parts, and length is 100. Puts them at 33.33 and 66.66. And then there is the choice of how many parts and offset from left to right.

I’ll mess around and see what I can find.

LOL

1 Like

I’m not good at heavy math like that so i won’t be able to help with that, but i know division will make this ALOT easier, you’re gonna need to divide something, maybe by amount of parts or something, if you had a 100 stud wall, and you wanted to add 5 parts to it, you can divide it by 5 to get that each part should be around 20 studs apart, so I BELIEVE
length / number of parts should give you a fair equation for the offset, i’m a little dumb though so :person_shrugging:

the math gets you a wall a bit like this, but if you want it to spawn wall studs on the edges im pretty sure you can probably use the rightvector/-rightvector if you want the easy way, otherwise itll require some adjustments with the offset

1 Like

Yooo I made it work, enough so that I can deal with it!! Thank you so much! I just needed a starting point and an ending point of the line and I have that! You have no idea how much time you saved me! Thank you so much!

P.S this is the math for anyone wondering:

OneStud.CFrame = cframe * CFrame.Angles(0, 0, math.rad(90)) * CFrame.new(Vector3.new(0, math.abs(script.Parent.Size.X/2), 0))
1 Like

You’re welcome, please send me that plugin link :star_struck:.

1 Like

Of course I will! Just take some time developing it to what we want, and I’ll put it into a private message when its done!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.