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

How do I make a GUI show when a block is touched? [Un-Answered!]

Exactly what the title says, here's what I tried:

script.Parent (function(hit)
	game.StarterGui.ScreenGui.GoodJob.Visible = true
wait(10)
	game.StarterGui.ScreenGui.GoodJob.Visible = false
end)

1 comment

0

http://wiki.roblox.com/index.php?title=Touched Also, you don't want to edit the StarterGui, you need to edit the player's PlayerGui.

2 answers

local debounce = true

script.Parent.Touched:connect(function (hit) --You missed "connect"
	if not hit.Parent:FindFirstChild("Humanoid") then return end --Check to see if it's a player.
	if not debounce then return end
	debounce = false --Debounce prevents the function being called multiple times.
	game.Players:FindFirstChild(hit.Parent.Name).PlayerGui.ScreenGui.GoodJob.Visible = true --PlayerGui must be edited, NOT ScreenGui. ScreenGui isn't the live GUI.
	wait(10)
	game.Players:FindFirstChild(hit.Parent.Name).PlayerGui.ScreenGui.GoodJob.Visible = false
	debounce = true
end)

I'm Aurum, and you're welcome.

The guy above forgot something...

Lemme get this right, if a someone touches a brick, then a GUI pops up?? If so, then copy this:

--PUT THIS IN A LOCALSCRIPT Inside the brick inside the player
brick = game.Workspace. --Complete the path to the brick
Gui = game.Players.LocalPlayer.PlayerGui --Complete the path to the Gui.
time = 10 --Waits 10 seconds before being allowed to be touched again. You can change this.
debounce = true --Leave this alone

script.Parent.Touched:connect(function(hit) --Aurum forgot the Touched event...
	if debounce == true then
		debounce = false
		if hit.Parent.Name == game.Players.LocalPlayer.Name then
			Gui.Visible = true
		end --Ends the second if
	end --Ends the first if
	wait(time)
	debounce = true
end)

5 comments

0

Why your script is wrong: 1) This is from a server script, as referenced at line 1, script.Parent. Your script at line 3 contains LocalPlayer, which is a LocalScript variable.

0
  1. I fixed the Touched event. 3) You didn't reset debounce to true so this function is non-reusable.
0

Thanks for the debounce indication, BUT, I even stated, in line 1 to put it in a LocalScript. You should use LocalScripts to avoid any lag in servers, and also use them in Gui's (Recommended).

0

You would have to set brick equal to game.Worspace, etc. and put that script within the player. Local Scripts in workspace don't execute any code.

0

Thanks for telling me, I didn't know that.

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