Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I add a design the message with a background or like a decal with it?

Asked by 10 years ago

I finished the script and it went great for my game. But when a player wins all it pops up is the player winning, but it doesn't have a design for it. Is there any way I can add a decal to the message for when a player win. This is a script:

local checkpoint1 = game.Workspace.Checkpoint1
local checkpoint2 = game.Workspace.Checkpoint2
local checkpoint3 = game.Workspace.Checkpoint3

local redLight = game.Workspace.StartLight.RedModel.LightBulb.PointLight
local yellowLight = game.Workspace.StartLight.YellowModel.LightBulb.PointLight
local greenLight = game.Workspace.StartLight.GreenModel.LightBulb.PointLight
local startBarrier = game.Workspace.StartBarrier

local raceInProgress = false

local lobbySpawn = game.Workspace.LobbySpawn
local trackSpawn = game.Workspace.TrackSpawn

local minimumPlayers = 2

function destroyCars()
    for _, object in pairs(game.Workspace:GetChildren()) do
        print(object.Name)
        if object.Name == "RaceCar" then
            print("This is the RC. Destroy it!")
            object:Destroy()
        end
    end
end

function createCars()
    for _, object in pairs(game.ServerStorage:GetChildren()) do
        local carCopy = object:Clone()
        carCopy.Parent = game.Workspace
        carCopy:MakeJoints()
    end 
end


function showVictoryMessage(playerName)
    local message = Instance.new("Message")
    message.Text = playerName .. " has won!"
    message.Parent = game.Workspace
    wait(2)
    message:Destroy()
end

function checkpoint1hit(otherPart)
    print("Checkpoint 1")
    print(otherPart.Name)
    if otherPart ~= nil and otherPart.Parent ~= nil and otherPart.Parent:FindFirstChild("Humanoid") then
        print("Someone hit me!")
        if not checkpoint1:FindFirstChild(otherPart.Parent.Name) then
            local playerTag = Instance.new("StringValue")
            playerTag.Parent = checkpoint1
            playerTag.Name = otherPart.Parent.Name
        end

        if checkpoint3:FindFirstChild(otherPart.Parent.Name) and raceInProgress then
            print("Player wins!")
            raceInProgress = false
            showVictoryMessage(otherPart.Parent.Name)
        end
    end
end

function checkpoint2hit(otherPart)
    print("Checkpoint 2")
    print(otherPart.Name)
    if otherPart ~= nil and otherPart.Parent ~= nil and otherPart.Parent:FindFirstChild("Humanoid") then
        print("Someone hit me!")
        if not checkpoint2:FindFirstChild(otherPart.Parent.Name) and checkpoint1:FindFirstChild(otherPart.Parent.Name) then
            local playerTag = Instance.new("StringValue")
            playerTag.Parent = checkpoint2
            playerTag.Name = otherPart.Parent.Name
        end
    end
end

function checkpoint3hit(otherPart)
    print("Checkpoint 3")
    print(otherPart.Name)
    if otherPart ~= nil and otherPart.Parent ~= nil and otherPart.Parent:FindFirstChild("Humanoid") then
        print("Someone hit me!")
        if not checkpoint3:FindFirstChild(otherPart.Parent.Name) and checkpoint2:FindFirstChild(otherPart.Parent.Name) then
            local playerTag = Instance.new("StringValue")
            playerTag.Parent = checkpoint3
            playerTag.Name = otherPart.Parent.Name
        end
    end
end

checkpoint1.Touched:connect(checkpoint1hit)
checkpoint2.Touched:connect(checkpoint2hit)
checkpoint3.Touched:connect(checkpoint3hit)



function startLightCycle()
    redLight.Enabled = true

    wait(1)

    redLight.Enabled = false
    yellowLight.Enabled = true

    wait(1)

    yellowLight.Enabled = false
    greenLight.Enabled = true
end

function removeBarrier()
    startBarrier.Transparency = 1
    startBarrier.CanCollide = false
end

function resetLights()
    redLight.Enabled = false
    yellowLight.Enabled = false
    greenLight.Enabled = false
end

function resetBarrier()
    startBarrier.Transparency = .5
    startBarrier.CanCollide = true
end

function clearCheckpoint(checkpoint)
    for _, object in pairs(checkpoint:GetChildren()) do
        if object.Name ~= "TouchInterest" then
            object:Destroy()
        end
    end
end

function teleportPlayers(target)
    for _, player in pairs(game.Players:GetChildren()) do
            while player.Character == nil do
                wait()
            end
        local character = player.Character
        local torso = character:WaitForChild("Torso")
        torso.CFrame = target.CFrame
    end
end

wait(10)

while true do
    -- wait for enough players before we start the game
    while game.Players.NumPlayers < minimumPlayers do
        wait()
    end

    -- setup racetrack  
    -- turn off all lights
    resetLights()

    -- reset barrier
    resetBarrier()

    -- create all cars
    createCars()

    -- clear all checkpoints
    clearCheckpoint(checkpoint1)
    clearCheckpoint(checkpoint2)
    clearCheckpoint(checkpoint3)

    -- teleport all players to the racetrack
    teleportPlayers(trackSpawn)

    wait(5)

    -- start race
    -- start light cycle
    startLightCycle()

    -- remove barrier
    removeBarrier()

    raceInProgress = true

    -- wait for race to finish 
    while raceInProgress == true do
        wait()
    end

    wait(2)

    -- delete all cars
    destroyCars()

    wait(2)

    -- teleport all players to the lobby
    teleportPlayers(lobbySpawn)

    wait(10)
end

2 answers

Log in to vote
1
Answered by 10 years ago

Sorry if I did not give a good explanation. :(

Judging from what your saying, you would probly need to use the ImageLabel, or the ImageButton, let me explain the two;

What ImageLabel does is like a regular TextLabel GUI, it's just there, and you can't interact [meaning Clicking, but you can drag if you have set the properties to do so] like you would for a TextButton, or in this case, the ImageButton.

What ImageButton does is like the TextButton GUI, where you can interact [meaning you can Click it, and connect it with a function using some-what like the MouseButton1Down event], here's an example of what I mean;

local TextButton = script.Parent:WaitForChild("TextButton")

TextButton.MouseButton1Click:connect(function()
if TextButton then
print("Clicked! :D")
end
end)

And as you'll see, when you click the TextButton, it will fire that event, and that's what the ImageButton will simply do, but for it you can add a Decal! But sadly, you can't use Text for it. The property for the Image is ImageButton.Image = "http://www.roblox.com/asset/?id=num, as you'll see in the Properties section of the GUI. Hope this helped!

Ad
Log in to vote
1
Answered by
Trewier 146
10 years ago

From a quick glace at your code, you are using a Message Instance(local message = Instance.new("Message")) to display your message. As they don't support images in them, you would have to create a custom gui to show your message.

Now there are several ways to attempt what I am suggesting; either you could build the gui before hand, and make it not visible, OR you could build a new gui each time you wanted to view the message.

Solution One:

Possible gui layout:

StarterGui
   -ScreenGui
      -Frame
         -ImageLabel
     -TextLabel

showVictoryMessage function code:

function showVictoryMessage(playerName)
    player = game.Players:FindFirstChild(playerName)
    screengui = player.PlayerGui.ScreenGui
    screengui.Frame.TextLabel.Text = playerName .. "has won!"
    for e = 1,0,0.05 do
            screengui.Frame.Transparency = e
        wait(0)
    end
    wait(1.5)
    for e = 0,1,0.05 do
            screengui.Frame.Transparency = e
        wait(0)
    end
end

Or we could go solution two:

Solution Two:

showVictoryMessage function code:

function showVictoryMessage(playerName)
    player = game.Players:FindFirstChild(playerName)
    createGui(player.PlayerGui)
    screengui = player.PlayerGui.ScreenGui
    screengui.Frame.TextLabel.Text = playerName .. "has won!"
    for e = 1,0,0.05 do
            screengui.Frame.Transparency = e
        wait(0)
    end
    wait(1.5)
    for e = 0,1,0.05 do
            screengui.Frame.Transparency = e
        wait(0)
    end
end

createGui function code:

function createGui(playerGui)
    screengui = Instance.new("ScreenGui",playerGui)
    frame = Instance.new("Frame",screengui).Size = UDim2.new(1,0,0.1,0)
    imageLabel = Instance.new("ImageLabel",frame).Size = UDim2.new(1,0,0,0)
    wait()
    imageLabel.Size = UDim2.new(1,0,0,imageLabel.AbsoluteSize.X)--kind of a trick to get x and y the same
    imageLabel.Image = "IMAGEURLHERE"
    textLabel = Instance.new("TextLabel",frame).Size = UDim2.new(0,frame.AbsoluteSize.X-imageLabel.AbsoluteSize.X,1,0)
    --Any Formatting to the TextLabel/Frame/ImageLabel would be done HERE
end

P.S. createGui would be a function in your script that you have above.

I hope this helped you with your problem, and if you have any questions, feel free to ask.

Have a nice day, iLiminate | Troy

0
Thank you sir. User#5689 -1 — 10y

Answer this question