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

How do I make text appear on the screen when a part is clicked?

Asked by 3 years ago

So far, when I click the part (the 'door') the screen flashes as I ask it to. However, I want the text to appear afterwards for two seconds. Anybody know what mistakes I have made here? Answers would be greatly appreciated.

-- VARIABLES --
colcor = game.Lighting.ColorCorrection
local can = script.Parent.Parent.can
can = true
local replicatedstorage = game.ReplicatedStorage
local text = replicatedstorage.TextLabel
local textclone = text:Clone()      

-- USER CLICKS ON DOOR --
script.Parent.MouseClick:connect(function()

    if can == true then

            can = false 

            colcor.Brightness = -0.6
            wait(.4)
            colcor.Brightness = 0.6
            wait(.4)
            colcor.Brightness = -0.6
            wait(.4)
            colcor.Brightness = 0.6
            wait(.4)
            colcor.Brightness = -0.2
            wait(.4)
            textclone.Parent = game.StarterGui["DOOR PROMPT"]
            textclone.Visible = true
            wait(2)
            textclone:Destroy()
            can = true

    end

end)
0
Are you using a server script or local script? Dovydas1118 1495 — 3y
0
server script mecatno22 4 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

You are not supposed to clone it to the StarterGui, but actually the PlayerGui. The PlayerGui is located in game.Players.PLAYERNAME.PlayerGui

  • Switch PLAYERNAME to the player's name. As you are on a server script, you would have to get the localplayer, and then simply clone it to their PlayerGui.
Ad
Log in to vote
0
Answered by 3 years ago

So. After talking via the community chat, I know how to solve the issues. Here's how you solve it. GUIs are LocalScripts because (if using StarterGui) they immediately replicated to the LocalPlayer.PlayerGui. A way to solve that is to use Remote Events. There is nothing wrong here apart from some inefficient methods. Also do not use a value, use a variable.

Server Script

colcor = game.Lighting.ColorCorrection
local debounce = false --Put a better name rather than 'can'.
can = true
local remoteEvent = game.ReplicatedStorage.RemoteEvent 

script.Parent.MouseClick:Connect(function(click)
    if debounce then --Alternative: if debounce == true
        debounce = true
            colcor.Brightness = -0.6
            wait(.4)
            colcor.Brightness = 0.6
            wait(.4)
            colcor.Brightness = -0.6
            wait(.4)
            colcor.Brightness = 0.6
            wait(.4)
            colcor.Brightness = -0.2
            wait(.4)
        remoteEvent:FireClient(game.Players:GetPlayerFromCharacter(click))
        debounce = false
    end
end)

Local Script

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    local plrGui = game.Players.LocalPlayer.PlayerGui
    plrGui["DOOR PROMPT"].TextLabel.Visible = true
end)

(Minor Nitpicks: Do not use connect as it is deprecated. Use Connect instead.)

Answer this question