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

Help telling a local script that a block was touched?

I cannot figure out how to tell a local script that a certain block was touched, and trigger an event to open up a gui. No need for a huge block of code, just give me a short run down of how I should do it. Thanks in advance!

1 answer

✓ Accepted answer

Well, i'm not sure what you mean by this, do you mean telling the localscript what block the character touched, or having a preset block with a touch event telling the localscript it was touched?

-- Localscript
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character
local block  = game:GetService'Workspace':WaitForChild("Part")
local gui = script.Parent  -- Put localscript inside gui
gui.Visible = false
local debounce = false

block.Touched:connect(function(p)
	if debounce then return end
	debounce = true
	local humanoid = p.Parent:FindFirstChild'Humanoid'
 	if humanoid and p.Parent == character then
		gui.Visible = true
	end
	debounce = false
end)



3 comments

1

I mean a preset block with a touch event. Sorry. And this is a singleplayer game as well. If that helps

0

Well if that's what you mean, then the above script should work perfectly, just parent it inside the gui

1

K thanks!

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