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

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

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

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)

10 comments

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

1

shut up infocus maybe he did act smart and gave PARTIAL code cause the guy didnt even try

1

infocus, your a bloody idiot

1

btw, its me smiley_face on sh discord, still infocus may be the goldfish

0

o sweet i got sum upvotes

1

ur welcome

0

thank you

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.

0

Sorry for the incorrect answer, I was in a rush and I didn't test it out.

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.

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.

6 comments

0

I made an even simplier script.

0

Once again, read the question carefully.

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

0

@Infocus, I was a beginner then, relax.

0

i know this thing's over a year but im looking at my older answers.

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.

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