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

how to see if a player is standing on a part?

Asked by
14dark14 167
4 years ago

I will make a script that will give the player a tool when he is standing on a part Example - player steps on a plate and he gets a sword and when he steps off the sword will disappear.

I will script all of that tool giving stuff myself, but I don't have any clue on how to see when the player is on the part.

I don't think I can just use a Touched event, because it will only detect the player stepping on the platform and not stepping off.

2 answers

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The above code detects whether a player has a humanoid if it does then it will read true once the player has stepped of a part.

local debounce = true
script.Parent.TouchEnded:Connect(function(hit)
    if debounce then
    if hit.Parent:FindFirstChild("Humanoid") then
        debounce = false
          wait(1)
        print ("Player stepped on a part")
        end
    end
end)
1
Please stop feeding people wrong information. Answering fast isn't answering smart. This will error anyways because you didn't close the conditional statement and the event Infocus 144 — 4y
1
shut up infocus maybe he did act smart and gave PARTIAL code cause the guy didnt even try greatneil80 2647 — 4y
1
infocus, your a bloody idiot User#22722 20 — 4y
1
btw, its me smiley_face on sh discord, still infocus may be the goldfish User#22722 20 — 4y
View all comments (6 more)
0
o sweet i got sum upvotes User#22722 20 — 4y
1
ur welcome greatneil80 2647 — 4y
0
thank you User#22722 20 — 4y
0
Idk who any of you are. He started answering on my thread with wrong info and then nearly copied another answer afterwards. Go ahead and support the wrong answers. This is why people never learn because you guys are too scared to correct them. Infocus 144 — 4y
0
Sorry for the incorrect answer, I was in a rush and I didn't test it out. JesseSong 3916 — 4y
0
Also I still wasn't that good at scripting a year ago, so calm your self. Everyone improves as they get older at something. JesseSong 3916 — 2y
Ad
Log in to vote
0
Answered by
Infocus 144
4 years ago

You can use TouchEnded.

local sp = script.Parent

sp.Touched:connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") then -- Check if its a player
    --give weapon
    end
end)

sp.TouchEnded:connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") then -- Checks for player
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)  -- Gets player from character
        player.Backpack:findFirstChild("TOOLNAME"):Destroy() -- Destroys tool
    end
end);

There are more efficient ways, but this is fine where you're at.

0
I made an even simplier script. JesseSong 3916 — 4y
0
Once again, read the question carefully. Infocus 144 — 4y
0
and bruh, please stop editing your script just to copy other people's answers. You got me dead. First you use .Touched now now TouchEnded wdh Infocus 144 — 4y
0
@Infocus, I was a beginner then, relax. JesseSong 3916 — 2y
View all comments (2 more)
0
i know this thing's over a year but im looking at my older answers. JesseSong 3916 — 2y
0
Also your code is very inneficient. You're using the lower-case c for :Connect, also, there's  no debounce, so essentially, the script will work once, then it error since there's no tool afterwards. JesseSong 3916 — 2y

Answer this question