Basically i'm trying to make brick that when clicked when clicked, moves a certain model from the serverstorage into the workspace, waits for a little bit, then enables a certain script and then when the block is clicked again it does the reverse moves said model from the workspace back into the serverstorage from the worskpace, waits for a little bit then disables said script. Thanks to viral moose and Scriptree i've learnt how to do these specific functions seperately but I seem to be having alot of trouble joining them together under one script :c
Here are the two scripts (note:They need to both function under one clickdetector brick for what I'm trying to create out of this. I know one's for a gui button and another is for a clickdetector brick
local script1 = workspace.script1 -- Put location of your script you want to enable/disable function onButtonClicked() script1.Disabled = false end script.Parent.MouseButton1Down:connect(onButtonClicked)
^credit to viralmoose for providing and
local serverstorage = game:GetService("ServerStorage") -- serverstorage is the service to store whatever you want in, Lighting was used before ServerStorage was made local model = serverstorage:WaitForChild("cheese") -- replace "cheese" with the name of the model under serverstorage local brick = script.Parent -- variable for the parent of the script, which is what the clickdetector is going to be under local detector = Instance.new("ClickDetector", brick) -- creating a clickdetector, which is used to be able to click a specific part, and parenting it to the script's parent. local isinwork = false -- creating debounce for later usage --[[You have to already have the model positioned as you want it to be shown as, in serverstorage, when it's parented to workspace it will be shown in the position you had it at when u stored the model in serverstorage]]-- function moveModel() -- function that will be called when someone clicks the part if not isinwork then -- checking if the debounce is false, if it is then it will parent it to workspace model.Parent = game.Workspace isinwork = true -- here it is setting the debounce to true so when it's clicked again it is parented to serverstorage else -- if the debounce is true then it will parent it to serverstorage model.Parent = serverstorage isinwork = false -- here it is setting the debounce to false so when it's clicked again it is parented to workspace end end detector.MouseClick:connect(moveModel) -- calling the function when the brick has been clicked
^credit to Scriptree for providing.
I'm not very experienced at all in making scripts from scratch on ROBLOX, I only know some of the basic terminology (but even then, I don't know which terminology are really deemed as "basic" so you can see my struggle here.)
Help would be very much appreciated and I'll be sure to credit you properly if you can help me find a working solution. :D
First of all, don't use other peoples scripts(unless its for learning purposes of course!), no one ever made a good game without making their own scripts and learning, plenty of resources out there, start at (wiki.roblox.com).
[[QUICK EXPLANATION]] Basically I combined the two functions and had one brick call that big function, let me know if I need to elaborate more of this doesn't work.
--ORIGINAL FUNCTION 1 local script1 = workspace.script1 -- Put location of your script you want to enable/disable function onButtonClicked() script1.Disabled = false end script.Parent.MouseButton1Down:connect(onButtonClicked)
--ORIGINAL FUNCTION 2 local serverstorage = game:GetService("ServerStorage") -- serverstorage is the service to store whatever you want in, Lighting was used before ServerStorage was made local model = serverstorage:WaitForChild("cheese") -- replace "cheese" with the name of the model under serverstorage local brick = script.Parent -- variable for the parent of the script, which is what the clickdetector is going to be under local detector = Instance.new("ClickDetector", brick) -- creating a clickdetector, which is used to be able to click a specific part, and parenting it to the script's parent. local isinwork = false -- creating debounce for later usage --[[You have to already have the model positioned as you want it to be shown as, in serverstorage, when it's parented to workspace it will be shown in the position you had it at when u stored the model in serverstorage]]-- function moveModel() -- function that will be called when someone clicks the part if not isinwork then -- checking if the debounce is false, if it is then it will parent it to workspace model.Parent = game.Workspace isinwork = true -- here it is setting the debounce to true so when it's clicked again it is parented to serverstorage else -- if the debounce is true then it will parent it to serverstorage model.Parent = serverstorage isinwork = false -- here it is setting the debounce to false so when it's clicked again it is parented to workspace end end detector.MouseClick:connect(moveModel) -- calling the function when the brick has been clicked
--NEW SCRIPT --First let's declare our variable from both scripts! -------Variables brick = game.Workspace.brick -- put the path to brick HERE local serverstorage = game:GetService("ServerStorage") local model = serverstorage:WaitForChild("cheese") local detector = Instance.new("ClickDetector", brick) --THIS IS THE ONE CLICKABLE BRICK local script1 = game.Workspace.script1 local isinwork = false --Debounce Variable --Next we need our event, which you specified as the click on the clickdetector, we will just attach a big function to this that has both functions combined detector.MouseClick:connect(function() if not isinwork then -- checking if the debounce is false, if it is then it will parent it to workspace model.Parent = game.Workspace isinwork = true -- here it is setting the debounce to true so when it's clicked again it is parented to serverstorage else -- if the debounce is true then it will parent it to serverstorage model.Parent = serverstorage isinwork = false -- here it is setting the debounce to false so when it's clicked again it is parented to workspace end -- UPDATE: FORGOT TO CLOSE THE IF STATEMENT SORRY :P! --END OF FIRST FUNCTION | BEGINNING OF NEXT FUNCTION script1.Disabled = false end) -- Close the parenthesis