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

How do I make a script where upon clicking a box/chest opens?

Asked by 6 years ago
Edited 6 years ago

You've probably seen this in many games. Upon clicking a treasure chest, it opens up (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.

I forgot to mention, the box named "Pandora" which is the script.Parent, contains multiple parts. The top lid of pandora known as "Top" contains 3 multiple parts. Sorry, I forgot to make that clear.

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:

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)

Thank you!

0
You need to access the parts that form the lid withing the model then change its CFrame. User#5423 17 — 6y

1 answer

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

Here you go. When moving or re-positioning models, you have to use the :SetPrimaryPartCFrame() method.

function onClicked(playerWhoClicked)
    script.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Top.Position
,Vector3.new(0,90,75)))

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

Sorry for the sloppy lines, but the website wouldn't adjust for its length.

0
Oh. I tried this script, but I got an error: 14:48:21.115 - Position is not a valid member of Model crystalclay 70 — 6y
0
I'm not sure why you received that error, as it works properly for me. Gey4Jesus69 2705 — 6y
0
Ooh, I forgot to mention that the top lid includes multiple parts. crystalclay 70 — 6y
Ad

Answer this question