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

I might be dumb but i cant figure out how to make my gui close?

hey there, i have turned to scripting helpers NOT for a request but a start/Explanantion on why my script will NOT delete my gui?

i have an on touched event triggered when a player touches the part but the gui will not remove itself after a said amount of time, its frustrating because i also cannot find any help on google, they only help with touched event with a gui you manually close with Mouse Click, i'll explain a little more...

my part is in the workspace spawned in via debris, then when a player touches it, it counts as a point toward money, which works perfectly in server and client mode. but i want there to be a gui popup that says "you picked up...." simply because the player doesnt need to press F like they need to for my NPCs, so they wont exactly know they picked up anything. my GUI appears on screen when touched, but i can't find a way to DELETE it or make it INVISIBLE after say... 3 seconds.

i have tried to have the gui deleted after 3 seconds but when i enter the game it deletes in all my debris after 3 seconds before i pick it up, my issue being i really cant find a local player, to delete it so it deletes itself after 3 seconds in the Debris, instead of player GUI, i feel dumb like this is very easy but i am missing something. is this a local script?

any help would be appreciated.

EDIT: this is the code: sorry if it is a mess lol i am a little lost

local Part = script.Parent
local DBounce = true


Part.Touched:connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") and DBounce then 
		DBounce = false
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if  player.PlayerGui:FindFirstChild("Notice") then 
			player.PlayerGui.Notice.TextLabel.Visible = true
			wait(3)
			player.PlayerGui.Notice.TextLabel.Visible = false
		end
		wait()
		DBounce = true
	end
end)

4 comments

2

Could you show us the script you had for this? It'd be much help for us to solve your issue.

0

yes, please provide the code 

0

i posted it

0

you should change screen gui elements from the client

1 answer

✓ Accepted answer

Okay, just to start off, if this is a server script, they can't go into a player's GUI. So make sure this is a local script! Also, game.Players:GetPlayerFromCharacter is useful, but pops up errors sometimes saying it's a nil value (it works both ways, but the errors would create some issues later on with lag). Other than that, this code should work. (Note, :connect is deprecated. Best to use :Connect instead)

--Make sure it's a local script!
local Part = game.Workspace.InsertThePartNameHere --Insert part name
local DBounce = true


Part.Touched:Connect(function(hit) -- Use :Connect. It's lowercase form is deprecated!
    if hit and hit.Parent:FindFirstChild("Humanoid") and DBounce then 
        DBounce = false
        if hit.Parent == game.Players.LocalPlayer.Character then --To avoid errors. 
           script.Parent.TextLabel.Visible = true --Changed it for local script
            wait(3)								--I want you to figure out where this goes.
             script.Parent.TextLabel.Visible = false	--Hint(it's the textlabel's parent or GUI)
        end
        wait()
        DBounce = true
    end
end)

10 comments

0

that is the issue, i cant figure out how to make it invisible/destroy after 3 seconds.

0

Yeah. I fixed it with that. Ur issue was that it has to be a local script in a GUI, not in a part on workspace.

0

thanks but, i put the gui in starter gui and when i hit the part it either doesnt open or anything, i have to remove "wait (3)" and the script.Parent.TextLabel.Visible = false, then it works, but doesnt close. when i put it back it doesnt open :/ i will figure it out eventually xD

0

It’s not supposed to be in the starter GUI, it should be in the Notice GUI u had

0

it is. but when the part is touched it does not show up with the wait, and the frame= false part. when i remove it, it shows up but doesnt close.

0

did u copy and paste the source or did u type it by hand? Cuz if u chose the

0

to type, you may have made a grammatical error

0

lua doesn't care about whitespace you can even line break between "wait" and "(3)" it doesn't matter one bit

0

i wrote the code myself, if you test it yourself i believe you will see what i mean

0

i have found my error, i have multiple of the same part. i am quite dumb tbh, i tested it on one part.

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