I'm trying to make a GUI pop up when you step on this brick, holding a gun. I already have the GUI, and the script (Thanks MrNicNac), but I don't know how to access the GUI. Here's the script:
01 | local toolname = "Luger, Colt 45" |
02 | script.Parent.Touched:connect( function (hit) |
03 | if hit.Parent then |
04 | local player = Game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if player then |
06 | if player.Character:FindFirstChild(toolname) then |
07 | -- Where GUI goes |
08 | end |
09 | end |
10 | end |
11 | end ) |
And plus, is there a way to make it only once, or once in a certain amount of time?
Using the code you have, you would access the player's PlayerGui simply by going player.PlayerGui.MYGUI
"And plus, is there a way to make it only once, or once in a certain amount of time?"
Edit:
Yes, indeed there is. In order to do this, you'll need to use some type of object that is to be looked for when the event fires. In this case, I'm using a IntValue
.
01 | local toolname = "Luger, Colt 45" |
02 | script.Parent.Touched:connect( function (hit) |
03 | if hit.Parent then |
04 | local player = Game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if player and not player:FindFirstChild( "No" ) then |
06 | if player.Character:FindFirstChild(toolname) then |
07 | local gui = player.PlayerGui.MyGUI |
08 | local no = Instance.new( "IntValue" , player) |
09 | no.Name = "No" |
10 | Spawn( function () |
11 | wait( 10 ) -- Player can only use the button once every 10 seconds |
12 | no:Destroy() |
13 | end ) |
14 | end |
15 | end |
16 | end |
17 | end ) |
Line 10 basically allows the code to continue running while the scope (the function) runs at it's own pace. You can get this effect a variety of ways, using game.Debris:AddItem(no, 10)
or by using the delay function.
Good luck!
Put at the top
1 | debounce = false |
In the script.
1 | If debounce = = false then |
2 | debounce = true |
To access the GUI. Do:
1 | player.PlayerGui.GUINAME |
At the end, put
1 | debounce = false |