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

How can i show a frame/text when a player hits a part?

Asked by 3 years ago
Edited 3 years ago

i want to make an gui appear when a player hits a part the code i am using is this:

local TextLabel = game.StarterGui.ScreenGui.TextLabel
local Frame = script.Parent.Parent.Frame
local plr = game.Players.LocalPlayer

Frame.Touched:Connect(function(hit)
    if hit.Name == plr then
        game.StarterGui.Waith.TextLabel.Visible = true
        wait(1)
        TextLabel.TextTransparency = 0.3
        wait(1)
        TextLabel.TextTransparency = 0.2
        wait(1)
        TextLabel.TextTransparency = 0.1
        wait(1)             
        TextLabel.TextTransparency = 0
        wait(1)
        game.StarterGui.Waith.TextLabel.Visible = false     


    end
end)

Please Help

1 answer

Log in to vote
0
Answered by 3 years ago

So, the reason why this script doesn't work is because you are changing the Gui's in the StarterGui, the problem with this is that it doesn't represent the current Gui, which can be found in Player.PlayerGui. I'm not the best at explaining things, so here is a link to the PlayerGui on the roblox Dev Wiki

Anyways, with all that said and done, your script would look like this:

local plr = game.Players.LocalPlayer
local TextLabel = plr.PlayerGui.TextLabel
local Frame = script.Parent.Parent.Frame

Frame.Touched:Connect(function(hit)
    if hit.Name == plr then
        plr.PlayerGui.Waith.TextLabel.Visible = true
        wait(1)
        TextLabel.TextTransparency = 0.3
        wait(1)
        TextLabel.TextTransparency = 0.2
        wait(1)
        TextLabel.TextTransparency = 0.1
        wait(1)             
        TextLabel.TextTransparency = 0
        wait(1)
        plr.PlayerGui.Waith.TextLabel.Visible = false     


    end
end)

Let me know if you need any more help!

0
If the player were to hit the part ("Frame"), shouldn't you do "hit.Parent.Name" rather than "hit.Name" (this is in line 6). Player1_Joined 271 — 3y
0
Thank you ScootVulpes Retallack445 75 — 3y
Ad

Answer this question