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

How to fix or make a Open/close Gui script for a Gui Image button?

I tried making an open/close script for my GUI, but I just can't get my head around it.


local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local pump = game.ServerStorage.Part
local pump1 = game.Workspace.Part1
local isButtonDown = false
local Clonedpump
local selectionBox = Instance.new("SelectionBox")
local enabled = false
script.Parent.MouseButton1Down:connect(function()
	if enabled == false then
		enabled = true
	else 
		enabled = false
	end

	if enabled == true then
	mouse.Button1Down:connect(function()
		isButtonDown = true
		pump1.Parent = game.ServerStorage
		Clonedpump = pump:Clone()
		Clonedpump.Parent = game.Workspace
		mouse.TargetFilter = pump
		mouse.TargetFilter = Clonedpump
		Clonedpump.Position = mouse.Hit.p
		isButtonDown = false
		enabled = false
	end)
	repeat
		pump1.Parent = game.Workspace
		mouse.TargetFilter = pump1
		selectionBox.Adornee = pump1
		selectionBox.Color3 = Color3.new(0,255,0)
		selectionBox.Parent = pump1
		pump1.Position = mouse.Hit.p
		wait()
	until isButtonDown == true
	end
end)


1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local pump = game.ServerStorage.Part --The client cannot access ServerStorage, use ReplicatedStorage
local pump1 = game.Workspace.Part1
local isButtonDown = false
local Clonedpump
local selectionBox = Instance.new("SelectionBox")
local enabled = false
script.Parent.MouseButton1Down:connect(function()
   if not enabled then
      enabled = true
      wait()
      pump1.Parent = game.Workspace
      mouse.TargetFilter = pump1
      selectionBox.Adornee = pump1
      selectionBox.Color3 = Color3.new(0,255,0)
      selectionBox.Parent = pump1
repeat
      pump1.Position = mouse.Hit.p
      wait()
until not enabled
end
else
   enabled = false
   pump1.Parent = game.ServerStorage -- again, needs to be changed
end
end)

mouse.Button1Down:connect(function()
   if enabled then
 --       isButtonDown = true --redundant
        Clonedpump = pump:Clone()
        mouse.TargetFilter = pump
        mouse.TargetFilter = Clonedpump
        Clonedpump.Position = mouse.Hit.p
        Clonedpump.Parent = Workspace --It's best to set the parent last
   --     isButtonDown = false --redundant
   end
end)

Honestly, no idea if that will even work. You will still need to fix the couple things I marked.

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