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

How do I make a chest/box flip open upon clicking?

Asked by 6 years ago
Edited 6 years ago

You've probably seen this in many games. Upon clicking a treasure chest, it flips open (probably with an angelic sound effect and sparkles) and then reveals the treasure inside. I'm doing something very similar, except it is a Pandora's box, not a treasure chest.

The box named "Pandora" (a Model) which is the script.Parent, contains multiple parts. The top lid of Pandora is stored inside the model and is known as "Top". "Top", contains 3 different parts. I want to rotate the top lid, to make the box open after a player clicks.

When I try to rotate the top lid, using C-Frame I get this error in the output:

21:24:18.863 - Position is not a valid member of Model

Here is the script so far:

view source

function onClicked(playerWhoClicked)

    script.Parent.CFrame = CFrame.new(script.Parent.Top.Position, Vector3.new(0, 90, 75)) -- Here, I'm only trying to rotate it.

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Please let me know if anything in the question is unclear. Thanks in advance

1 answer

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

~~~~~~~~~~~~~~~~~

function onClicked(playerWhoClicked)

script.Parent.Part1.CFrame = CFrame.new(script.Parent.Top.Position, Vector3.new(0, 90, 75)) -- Here, I'm only trying to rotate it.

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

~~~~~~~~~~~~~~~~

Your script is trying to change the Position of the Model which the parts are in, which is impossible. script.Parent finds Pandora. script.Parent.Part1 (Or whatever you named one of the parts) finds the part inside pandora.

Simply copy and paste your line of code three times with the respective names and Vector3 values for each of the parts and it should work for you.

0
I tried doing this, however I got the error: "Part1/the real part name" is not a valid part of Model. crystalclay 70 — 6y
0
You're getting closer! script.Parent.THENAMEOFYOURPART! marsupicide 60 — 6y
0
That's what I did . crystalclay 70 — 6y
Ad

Answer this question