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

How to check if a player is touching a specific part? If so continue code?

Asked by
Nidoxs 190
9 years ago

Player presses key, if touching a certain part with a certain name then continue code, how would I do this?

01--doctorbenny2011 09/04/2016 15:45GMT
02 
03istouching = false
04local Player = game.Players.LocalPlayer
05repeat wait(.01) until Player.Character
06local Mouse = Player:GetMouse()
07local Animated = false
08 
09Player.Character["Left Leg"].Touched:connect(function(hit)
10    if hit then
11        if hit.Name == "Matress" then
12        istouching = true 
13        elseif hit.Name ~= "Matress" then
14        istouching = false
15        end
View all 26 lines...

2 answers

Log in to vote
1
Answered by 9 years ago

You might be able to use Touch and TouchEnded.

01tv = 0
02function pint()
03    print ("touch"..tv)
04    tv = tv +1
05end
06function upint()
07    print "touch ended"
08end
09script.Parent.Touched:connect(pint)
10script.Parent.Touched:connect(upint)

something like that should work. It won't work very well, but it will work.

0
But this local script will be inside the PlayerGui, I'm trying to check if the player is touching a part with a specific name FROM the players PlayerGui. Nidoxs 190 — 9y
Ad
Log in to vote
1
Answered by 9 years ago
01--doctorbenny2011 09/04/2016 15:45GMT
02 
03istouching = false
04local Player = game.Players.LocalPlayer
05repeat wait(.01) until Player.Character
06local Mouse = Player:GetMouse()
07local Animated = false
08 
09--UserInputFunction
10Matress.Touched:connect(function(touched) --Detects when touched & define matress
11    if touched.Parent.Humanoid == true then
12        istouching = true  
13    end
14end
15 
View all 27 lines...

Answer this question