Help with Scripting UI

Hello fellow reader! I need help scripting my UI, let me explain it as much as I can. So basically I want the UI to do this, when you hover over the button, it changes into a white button, and when you press on it the button turns blue. There are 3 buttons, a loadout button, a crate button and a shop button. I already have the script for the loadout button but, my problem is that I don’t know how to fix this. I want the script from the loadout button to do the same thing as this one. Here’s a video of what I want the shop and crate button to do.
robloxapp-20210425-2017320.wmv (528.9 KB)

Basically I’m just wondering if anyone knows a similar way to do this or help me do what I want the UI to do, also, here’s the explorer properties for the UI.
image

Here’s the script down below. I didn’t add the image ids because I didn’t want anyone to take my work. Anyways here’s the script.

local CratesButton = script.Parent.Parent.CratesButton
local ShopButton = script.Parent.Parent.ShopButton

script.Parent.MouseEnter:Connect(function()
	if script.Parent.Image == "Image" then
		script.Parent.Image = "Image"
	else
		CratesButton.TweenScript.Disabled = true -- Disables Hover Script for Crates Button
		ShopButton.TweenScript.Disabled = true -- Disables Hover Script for Shop Button
		script.Parent.Image = "Image"
		script.Parent:TweenSize(UDim2.new(0.148,0 ,0.068,0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, .2, false)-- Size Tweener
		script.Parent.ZIndex = 2
	end
end)

script.Parent.MouseLeave:Connect(function()
	if script.Parent.Image == "Image" then
		script.Parent.Image = "Image"
	else
		script.Parent.Image = "Image"
		script.Parent:TweenSize(UDim2.new(0.127, 0,0.061, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, .2, false)-- Size Tweener
		script.Parent.ZIndex = 1
		CratesButton.TweenScript.Disabled = false -- Enables Hover Script for Crates Button
		ShopButton.TweenScript.Disabled = false -- Enables Hover Script for Shop Button
	end
end)

script.Parent.MouseButton1Click:Connect(function()
	CratesButton.TweenScript.Disabled = true -- Disables Hover Script for Crates Button
	ShopButton.TweenScript.Disabled = true -- Disables Hover Script for Shop Button
	CratesButton:TweenSize(UDim2.new(0.127, 0,0.061, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, .2, false)-- Size Tweener
	ShopButton:TweenSize(UDim2.new(0.127, 0,0.061, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, .2, false)-- Size Tweener
	script.Parent.ZIndex = 2
	script.Parent:TweenSize(UDim2.new(0.148,0 ,0.068,0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, .2, false)-- Size Tweener
	script.Parent.Image = "Image"
end)

You should probably do this in a local script instead. Whats not working with this script?

1 Like

So, what’s not working with the script is I want to know if there’s a way I can have the same working script but, without having to disable the crate and shop button’s script. Basically disabling the scripts from the other buttons makes it so they can enlarge as the loadout button does. I want the last sentence to happen but without needing to disable it. Also, I will change it to a LocalScript.

You can put the other code inside a function then call them whenever you need to.

Example:

local function tween()
-- the code inside of a disabled script
end

local function tween2()
-- the code inside another disabled script
end

local button = script.Parent

button.MouseEnter:Connect(function()
tween()
end)

button.MouseLeave:Connect(function()
tween2()
end)

you should change this

to this

button.MouseEnter:Connect(tween)
button.MouseLeave:Connect(tween2)
1 Like