Is it possible to custom a TextButton’s click behavior?
Such as:
Custom Color for clicking
Disabling Click effect
Custom Hovering color
Besides creating a custom text button
Is it possible to custom a TextButton’s click behavior?
Such as:
Custom Color for clicking
Disabling Click effect
Custom Hovering color
Besides creating a custom text button
Sorry, deleted it because I didnt see
All good lol.
I want to and originally was going to make a system for custom click buttons, didn’t know if this would effect performance and would be a waste of time if it’s possible to just override the other stuff
Yes it’s possible, you can detect the click of the textbutton and manipulate it’s properties. If you want a smooth effect just use TweenService.
Sample script:
TextButton.MouseButton1Click:Connect(function()
TextButton.TextColor = Color3.fromRGB(255,255,0)
end)
For hovering, you could just do:
TextButton.MouseEnter:Connect(function()
end)
Yes, but he wants to not make scripts or a different text button
I know image buttons have a HoverImage
and PressedImage
, so you could have an image button with the images set for each and a text label over it.
Otherwise, you would have to code in the colors manually for a text button. I don’t think it’s very tough though. You could even have attributes so you don’t have to touch the code after setting it up.
Edit: it’s actually a little tough given you have to keep the pressedColor
when you hold the mouse button down, leave and then enter again without releasing…
Edit 2: AutoButtonColor
doesn’t actually keep the pressed color when leaving and entering, it just goes back to normal color. That makes simulating this trivial.
-- ButtonCustomColors.lua
--!strict
local function assertLevel(condition, message: string, level: number)
if condition then
return condition
else
error(message, level + 1)
end
end
local function buttonCustomColors(button: GuiButton)
button.AutoButtonColor = false
local normalColor = button.BackgroundColor3
local hoverColor = button:GetAttribute("HoverColor")
assertLevel(typeof(hoverColor) == "Color3", "attribute \"HoverColor\" is not of type Color3", 2)
local pressedColor = button:GetAttribute("PressedColor")
assertLevel(typeof(pressedColor) == "Color3", "attribute \"PressedColor\" is not of type Color3", 2)
local function toHover()
button.BackgroundColor3 = hoverColor
end
local function toPressed()
button.BackgroundColor3 = pressedColor
end
local function toNormal()
button.BackgroundColor3 = normalColor
end
local connections: {RBXScriptConnection}? = {
button.MouseEnter:Connect(toHover),
button.MouseLeave:Connect(toNormal),
button.MouseButton1Down:Connect(toPressed),
button.MouseButton1Up:Connect(toNormal)
}
local function disconnectAll()
if connections ~= nil then
for _, conn in connections do
conn:Disconnect()
end
button.BackgroundColor3 = normalColor
connections = nil
end
end
return disconnectAll
end
return buttonCustomColors
-- someScript.client.lua
local buttonCustomColors = require(path.to.ButtonCustomColors)
local someButton = path.to.Button
local stopCustomColors = buttonCustomColors(someButton)
-- when you don't want custom colors anymore,
stopCustomColors()
My bad I hadn’t read that part, well then I don’t think it’s possible without creating scripts.
I don’t mind scripting it, I just wanted to know if I could disable that from a script or not.
If I can’t I will probably just create a custom button system
Yeah, I think that you cant do it without scripting, if you will script, use mine, @goldenstein64 or @rambunctionzoro2 for a basic start.