Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I properly make a open/close trunk script?

Basically what i'm doing is making 2 models, and each time I click one model goes transparent and the other appears, and vice versa. But I can't get it to work properly.

function onClicked()
	open = false
	if open == false
		then game.Workspace.Model.Open.Properties.Transparency = 1
		game.Workspace.Model.Open.Properties.CanCollide = false
		game.Workspace.Model.Close.Properties.Transparency = 0
		game.Workspace.Model.Close.Properties.Cancollide = true
		
	end
end

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

1 answer

✓ Accepted answer

Create a model with both parts inside of it, add a ClickDetector to both the 'Open' and the 'Close' parts. Run this as a script inside the model.

script.Parent.Open.ClickDetector.MouseClick:connect(function()
	if script.Parent.Close.Transparency == 1 then
	script.Parent.Close.Transparency = 0
	script.Parent.Close.CanCollide = true
	script.Parent.Open.Transparency = 1
	script.Parent.Open.CanCollide = false
	elseif script.Parent.Close.Transparency == 0 then
	script.Parent.Close.Transparency = 1
	script.Parent.Close.CanCollide = false
	script.Parent.Open.Transparency = 0
	script.Parent.Open.CanCollide = true
	end
	end)

Hope this helps. Remember to mark this as answered if this helps, if not, reply to this in more detail in what the issue is.

6 comments

0

It works, but I want it to share one click-detector instead of 2 seperate ones, how would I do that? I tried to do this.

0

TrunkOpened = false function onClicked() if not TrunkOpened then script.Parent.Parent.Parent.Close.Part1.Transparency = 1 script.Parent.Parent.Parent.Close.Part2.Transparency = 1 script.Parent.Parent.Parent.Close.Part1.CanCollide = false script.Parent.Parent.Parent.Close.Part2.CanCollide = false TrunkOpened = true elseif TrunkOpened then script.Parent.Parent.Parent.Open.Part1

0

I'm not the most advanced scripter, and I'm not entirely sure it's possible in this instance. You want a trunk in which transfers parts, and to do so you'd need a ClickDetector for each part used. One to open the trunk and another to close.

0

I've modified the script in my answer to your specifications. You should only need a clickdetector in the 'Open' part this time.

0

So they share one clicker?

0

Should do, the only ClickDetector should now be in the part "Open.", if this answers your question, please mark this as "answered."

This discussion is preserved as it was. New answers, comments, and votes are closed.