Hello everyone! I’m making a main menu for my game and I ran into a pretty complicated problem that I can’t get out for myself. Before I made this post, I seached throughout the entire internet for an answer, and changed my code many times but it still doesn’t work.
I made a MouseEnter and MouseLeave thing, and it works perfectly fine, but I want to when i click some button, it goes to the color to the MouseEnter until I click another button, basically indicating that you selected that button, that in my view it’s fancier and it’s used on most games nowadays.
The problem is that when I change the color of the button, The MouseLeave goes and changes it’s color, making it useless (atleast it was before I change the code, and I think it’s the same problem yet but I don’t know)
I made a stringvalue on ReplicatedStorage named “MapSelected”, so when you click a button, the value changes to the button name, and I tried triggering the MouseLeave just when the value of the string is not as the same as button, but that logic didn’t work (and it’s perfect, why it doenst!!!)
Well, heres the script, any help is appreciated, I’m already frustated with this and it’s my second post without any answer
HoverEffects
local sound = script:WaitForChild("Hover sound test 3")
local replicatedStorage = game:GetService("ReplicatedStorage")
local selectedMap = replicatedStorage:WaitForChild("SelectedMap")
for i, button in pairs(script.Parent:GetChildren()) do
if button:IsA("ImageButton") then
button.MouseEnter:Connect(function()
local textButton = button:WaitForChild("Text")
button.ImageTransparency = 0
textButton.BackgroundColor3 = Color3.fromRGB(255,100,0)
textButton.TextColor3 = Color3.fromRGB(0,0,0)
sound:Play()
end)
button.MouseButton1Click:Connect(function()
selectedMap.Value = button.Name
if selectedMap.Value == button.Name then
button.MouseLeave:Connect(function()
local textButton = button:WaitForChild("Text")
button.ImageTransparency = 0
textButton.BackgroundColor3 = Color3.fromRGB(255,100,0)
textButton.TextColor3 = Color3.fromRGB(0,0,0)
end)
end
end)
end
end
I fixed something and discovered that when clicking some button it works perfectly and the button color is fixed, but when clicking another one, the button you pressed before dont change colors