Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to reset a part with a button?

Asked by 5 years ago
Edited 5 years ago

I'm making a domino game where if you knock them all over, you can press a gui button to stand all of them back up. The only thing is, I don't know where to start if I were to script this. Can I just move the group through a script? Would this stand them all back up?

0
So it is basically a "regen all dominoes" button? 123nabilben123 499 — 5y
0
Yes. I can script it, but I just don't know where to start. matiss112233 258 — 5y
0
Make a copy of the model and store it in ServerStorage. When you want to reset the model you remove the original model and replace it with the copied one. ScuffedAI 435 — 5y
1
At the start I'd make a table with all parts as keys, and the value the starting CFrame when the game starts, when you reset, you can restore those CFrames. User#834 0 — 5y
View all comments (5 more)
0
FloweryMonkey why not do what Kate said? Isn't that the same thing as replacing with CFrames but just positioning them at the right spot? 123nabilben123 499 — 5y
0
FlowerMonkey that seems unnecessarily tedious when you can just replace it with a clone. proqrammed 285 — 5y
1
Destroying and cloning a whole new object into the workspace is performance wise much worse, since it has to render out all instances, and render them back in. Otherwise you only have to update the CFrame which is a single thing to do User#834 0 — 5y
0
Eh, I guess that makes sense. But if it’s a simple game, it should be fine proqrammed 285 — 5y
0
Why not put the dominoes in the workspace but they are invisible then whenever you need them make a copy and set their cframe to the dominoes place and make them visible? 123nabilben123 499 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Put a localscript in the button. Put a duplicate of the dominos in ServerStorage. Put this in the script:

(Change the variables to the actual dominos, these are just directories I made up)

local DominosToReset = workspace.Dominos
local DominosInStorage = game.ServerStorage.Dominos


function leftClick()
    print("Button Click”)
        DominosToReset:Destroy()
        DominoReplacers = DominosInStorage:Clone()
        DominoReplacers.Parent = workspace
        DominosToReset = DominoReplacers
end

script.Parent.MouseButton1Click:Connect(leftClick)

The idea is that the dominos in ServerStorage are cloned to replace the old ones as they are deleted.

This was coded from my head, there may be errors.

Hope this helps you. Merry Christmas! :)

0
You should also set the DominosToReset to the cloned dominoes so you can destroy them after too 123nabilben123 499 — 5y
0
Good idea. Editing now proqrammed 285 — 5y
1
Don't use Lighting as storage. It's not meant for that at all. User#834 0 — 5y
0
Sorry, it’s just a bad habit proqrammed 285 — 5y
View all comments (3 more)
0
Why not put the dominoes in the workspace but they are invisible then whenever you need them make a copy and set their cframe to the dominoes place and make them visible? 123nabilben123 499 — 5y
0
That sounds like a hassle to write a script to change all the transparencies during runtime and I believe it wouldn’t improve anything, it might cause a performance downgrade too proqrammed 285 — 5y
0
That sounds like a hassle to write a script to change all the transparencies during runtime and I believe it wouldn’t improve anything, it might cause a performance downgrade too proqrammed 285 — 5y
Ad

Answer this question