So I'm making this crate where if you click it, it opens up to be a Coin or a Heart. Now, with the heart, it seems to be fine when I set the CFrame of it to the center of the crate (keep in mind the heart and coin have spinning scripts) and it goes to the desired center of the crate using CFrame. However, when the coin shows up, the coin appears to go above the crate rather than at the center like I intended it to (and I used CFrame, not Position). The problem is that since the coin and the heart have different meshes, the heart was spinning on the Y-axis while the coin was spinning on the X-axis, therefore I had to change the orientation of the coin to make the coin spin the right way. Doing so caused the conflict above.
possibleItems={"Coin","Heart"}
crate=script.Parent
parts=crate:GetChildren()
ori=script.ResetOrientation:clone()
for i,v in pairs(crate:GetChildren()) do
if v:IsA("Part") then
local click=Instance.new("ClickDetector")
click.Parent=v
click.MouseClick:connect(function(player)
local s=Instance.new("Sound")
s.Parent=crate.Center
s:Play()
s.PlayOnRemove=true
s.SoundId="rbxassetid://934993709"
crate:BreakJoints()
local currItem=game.ServerStorage:findFirstChild(possibleItems[math.random(1,#possibleItems)]):clone()
currItem.Parent=game.Workspace
savepos=crate.Center.CFrame
crate.Center:remove()
if currItem.Name=="Coin" then
currItem.AlwaysRot.Disabled=true
currItem.CFrame=savepos
if currItem.Orientation.Y~=90 then
currItem.Orientation=Vector3.new(0,90,-90)
end
else
currItem.CFrame=savepos
end
wait(3)
for i=1,5 do
wait(.05)
for i,v in pairs(parts) do
if v:IsA("Part") then
v.Transparency=0
end
end
wait(.05)
for i,v in pairs(parts) do
if v:IsA("Part") then
v.Transparency=1
end
end
end
crate:remove()
end)
end
end
