I want to know how to do that.
How do i code Wait Until LocalPlayer Touches Brick?
3 answers
you need an localscript inside the part you want to detect if touched and when you have it
you just need this code:
function Touched(part1) -- inside the brackets put the name of ur part
local h = part1.Parent:findFirstChild("Humanoid")
if h~=nil then
-- this is where your action goes
end
end
script.Parent.Touched:connect(Touched)
This code should help you.
First we need the part, so you can create and edit it to be however you want
Next we need to start coding :)
Insert a local script and use this code:
script.Parent.Touched:Connect(function(hit) --Detect when the part is touched
--Detect if humanoid exists
if hit.Parent:FindFirstChild("Humanoid") then
--This code executes when the player touches the part
print("Player touched part")
end
end)
.Touched only runs when the part is touched by anything. Another part, or the player.
A local script only runs on the client so the server or other players cannot see it. If you want other players or the server to see it, you need to use remote events.
These 2 answers didn't help me it just executes a code when localplayer touches a block instead of wait until localplayer touches a block, I had to do a workaround myself and it took me 10 hours to do so... :(
local untiltouchblock = 0
function Touched(part1)
local h = part1.Parent:findFirstChild("Humanoid")
if h~=nil and untiltouchblock == 0 then
untiltouchblock = 1
end
script.Parent.Touched:connect(Touched)
repeat wait() until untiltouchblock == 1
This discussion is preserved as it was. New answers, comments, and votes are closed.
