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

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

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

✓ Accepted answer

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!

2 comments

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).

0

Thank you ScootVulpes

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