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

Is it possible to make an error message with custom animations?

Hi so I was making my game and came across something which really bugged me, so in my game you have a value which is called "Cash" and you can buy stuff with it, but if you don't have enough it does absolutely nothing. I know many games use this cool error animations for example Theme Park Tycoon being one of them.

So I basically want a error message gui bar that appears at the top and when a player keeps clicking the error it scrolls down the other error you can see a good example of it in theme park tycoon. I already know how to use TweenPosition and I also know how to create a gui but I don't know how this would work. Please help.

I have already made the error animation when a player pressed the button and hasn't got enough money but everytime they press it again it just overlaps.

My code is here:

local button = script.Parent
local requiredCash = 1500 -- How much is required to buy it
local plr = game.Players.LocalPlayer
local leaderstats = plr:FindFirstChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")

button.MouseButton1Click:connect(function()
	if cash.Value >= requiredCash then
		-- this just gives the player the stuff they need
	else
		local gui = Instance.new("ScreenGui", plr:FindFirstChild("PlayerGui"))
		gui.Name = "ErrorBar"
		local error = Instance.new("TextLabel", gui)
		error.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		error.Text = "Error | You have insufficient funds"
		error.Size = UDim2.new(1, 0, 0, 50)
		error.TextWrapped = true
		wait(4) -- delay
		for i=0, 1, 0.1 do
			wait()
			error.BackgroundTransparency = i
		end
		gui:Remove()
	end
end)

It creates a nice error but it has no animations and every time someone spam clicks it, it just overlaps and looks ugly.

1 answer

You shouldn't use a variable named error, as error is an actual global function. Use, say, a variable named errorGUI.

This fx is actually really easy. Just create a boolean variable to tell whether the animation is playing or not.

local button = script.Parent
local requiredCash = 1500 -- How much is required to buy it
local plr = game.Players.LocalPlayer
local leaderstats = plr:FindFirstChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")

local errorIsPlaying = false --new variable

button.MouseButton1Click:connect(function()
    if cash.Value >= requiredCash then
        -- this just gives the player the stuff they need
    elseif not errorIsPlaying  then --checks if the animation is playing
	errorIsPlaying = true --sets the animation variable as true, so if the button is spammed it doesn't do anything

        local gui = Instance.new("ScreenGui", plr:FindFirstChild("PlayerGui"))
        gui.Name = "ErrorBar"
        local errorGUI = Instance.new("TextLabel", gui) --You shouldn't use "error" as a variable
        errorGUI.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
        errorGUI.Text = "Error | You have insufficient funds"
        errorGUI.Size = UDim2.new(1, 0, 0, 50)
        errorGUI.TextWrapped = true
        wait(4) -- delay
        for i=0, 1, 0.1 do
            wait()
            errorGUI.BackgroundTransparency = i
        end
        gui:Remove()
	errorIsPlaying = false --sets the animation variable as false, so it can be played again.
    end
end)

3 comments

0

I understand how this would work, but what I mean is that when you spam the button if you still get the error, they scroll down and eventually disappear

0

What do you mean?

0

For example on Theme Park Tycoon when you get an error it appears on the top of your screen, but if you keep getting the same error instead of overlapping each other it moves above or below it

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