Clickable drawer is not working

I am currently trying to make an alternative method for a clickable custom proximity prompt using ImageButtons. A BillboardGui shows up whenever the player’s mouse hovers over an object that has the name: “Drawer”. The BillboardGui includes an ImageButton which, once is clicked, is supposed to do the same function that the regular proximityprompt does when you press ‘E’ on the keyboard.

Here is the mouse local script:

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()  



game:GetService("RunService").Stepped:Connect(function(input)
	if mouse.Target then
		if mouse.Target.Name == "Drawer" then
			if mouse.Target.Show.Value == true then
				mouse.Target.Open.Enabled = true
			end
			if mouse.Target.Show.Value == false then
				mouse.Target.Close.Enabled = true
			end
			if game.ReplicatedStorage:FindFirstChild("Highlight") then
				game.ReplicatedStorage.Highlight.Parent = mouse.Target
				player.PlayerGui.BillboardGui.Enabled = true
				player.PlayerGui.BillboardGui.Adornee = mouse.Target
local drawereference = game.ReplicatedStorage.DrawerReference
				drawereference:FireServer(mouse.Target, mouse.Target.Show.Value) -- The 'Show' value is basically telling if the proximity prompt is the 'Close' proximity prompt, or the 'Open' proximity prompt.

			end
			else

				for i, v in pairs(workspace:GetDescendants()) do -- This just disables all the proximity prompts inside of the drawer.
		
				
					if v.Name == "Drawer" then
						v.Open.Enabled = false
						v.Close.Enabled = false

						player.PlayerGui.BillboardGui.Enabled = false
						player.PlayerGui.BillboardGui.Adornee = nil

						if v:FindFirstChild("Highlight") then
							
							v.Highlight.Parent = game.ReplicatedStorage
						end
					end
				end
			end
		end
end)

Here is the ImageButton script (btw the ImageButton is located inside a BillboardGui inside of the PlayerGui):

game.ReplicatedStorage.DrawerReference.OnServerEvent:Connect(function(p, drawer, val)

script.Parent.MouseButton1Click:Connect(function()
	local tweenservice = game:GetService("TweenService")
	local draweropen = tweenservice:Create(drawer, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {Position = drawer.OpenDrawer.Position})
	local drawerclose = tweenservice:Create(drawer, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {Position = drawer.ClosedDrawer.Position})
		if drawer:FindFirstChild("Show") then
		
			if val == true then
				print("true")
			drawer.Open.Enabled = false
			drawer.Show.Value = false
			drawer.Close.Enabled = true
			draweropen:Play()
			game.ReplicatedStorage.PlaySound:FireAllClients(game.ReplicatedStorage.Audios.Drawer)
		end
			if val == false then
				print("false")
			drawer.Open.Enabled = true
			drawer.Show.Value = true
			drawer.Close.Enabled = false
			drawerclose:Play()
				game.ReplicatedStorage.PlaySound:FireAllClients(game.ReplicatedStorage.Audios.Drawer)
		end
	end
	end)
	end)

Screen Shot 2022-10-23 at 12.56.14 PM
Output after opening and closing the drawer:

Ok so i dont see why you would want to make a drawer like that. Constantly checking if the mouse hits somethings and if its a drawer. I don’t think that is a good idea, and i really don’t see why you would use that. Imo it is way easier to use a simple click detector. Also for future work, i don’t think it is recommended to use mouse.hit. I think it is depricated, and if not it might be soon. The recommended would be to use a raycast that shoots a ray from the player’s mouse.

Agreed, you dont really need to do that since

  1. Waste of time

  2. You can make it more simple and have it do the same thing

Server Script with ClickDetector:

Opened = false
script.Parent.MouseClick:Connect(function()
if Opened == false then
Opened = true 
print("Opened") -- Remove and Add your script here for opening
elseif Opened == true then
Opend = false
print("Closed") -- Same with here for when closing
end

Same script with ProximityPrompt:

Opened = false
script.Parent.Triggered:Connect(function()
if Opened == false then
Opened = true 
print("Opened") 
elseif Opened == true then
Opend = false
print("Closed") 
end