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

How to detect if a player is on a block?

Hello again.

With reference to the question mentioned, how do I do it?

Let's say that I am standing on a block and if that is true, I want it to print "Hi". How could it be done?

Many thanks, RealCMDMinecraft

2 answers

✓ Accepted answer

You should use the Touched signal, like so:

workspace.hiPart.Touched:connect(function()
  print("hi")
end)

If you want to make this relative, use the following:

--Note that this script is a child of the part that says hi.

script.Parent.Touched:connect(function()
  print("hi")
end)

I think all of this will work. Note the Touched signal fires even if a different part touches hiPart.

If you want it to fire only when a player touches the block, use Humanoid's touched signal. I don't know how to use that signal, so that's why I used the regular BasePart's touched signal.

print ("Hi")

function onTouched(hit) 
	print("Brick Hit") 
	local human = hit.Parent:findFirstChild("Humanoid") 
	if (human ~= nil ) then 
			Brick.Transparency = 0.7 
			Brick.CanCollide = false 
			wait(4) -- this is how long the block can long
			Brick.CanCollide = true 
			Brick.Transparency = 0 
			-- a human has touched this door! 
			print("Human touched block") 
			-- test the human's name against the permission list 
		elseif (checkOkToLetIn(human.Parent.Name)) then 
			print("Human passed") 
			Brick.Transparency = 0.7
			Brick.CanCollide = false 
			wait(4) -- this is how long the block can long
			Brick.CanCollide = true 
			Brick.Transparency = 0 
		else human.Health = 0 -- delete this line of you want a non-killing block
		end 
	end 
end 

script.Parent.Touched:connect(onTouched)


Make sure to call the block "Brick" or call it however you want, but then replace the "Brick" in all these lines with what you want.

3 comments

0

May I ask something: "script.Parent.Touched:connect(onTouched)" what does it do? And when I run this code this error message popped up: Touched is not a valid member of Folder

0

It's the sign that a player has touched it, and it connects the script. You might have to renew the Touched term with the new script terms.

0

Well that's a private door, not a block that says hi when you touch it.

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