Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if a player is on a block?

Asked by 7 years ago

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

Log in to vote
0
Answered by
Podnf 22
7 years ago

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.

Ad
Log in to vote
0
Answered by 7 years ago
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.

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 RealCMDMinecraft 6 — 7y
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. ChristianSenpaii 29 — 7y
0
Well that's a private door, not a block that says hi when you touch it. Podnf 22 — 7y

Answer this question