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

How to remember if a player has touched a brick or not?

Hello, I am making a game where if the player steps on a brick it fades away (round based game), but whenever the debounce wait is over, the player can just jump on invisible bricks, abusing the cancollide.

Does anybody know how to remember if a player has touched a brick, and then to forget the data after a certain condition is met?

Thanks, ChickenCrat

1 answer

Maybe you can make a table of players that touched the brick then remove them from the table when the condition is met?

playersTouched = {} -- make a table

part.Touched:Connect(function(touchedPart)
	local player = game.Players:GetPlayerFromCharacter(touchedPart)
	if player then
		if not playersTouched[player.UserId] then --check if the player is in the table
        		playersTouched[player.UserId] = player --if not them add them
		end
	else
end

--if condition met then
	if playersTouched[player.UserId] then 
		playersTouched[player.UserId] = nil --remove them from the table
	end
end

Let me know if this works for you.

3 comments

0

Hello, I have tried the code, and it didn't seem to work for me. I got the following error : Workspace.Spleef.Part.Detector.TouchData:14: attempt to index nil with 'UserId'

0

Could you edit your post to include the code surrounding the line where the error occurred?

0

Sorry for the confusion, I don't know how to edit posts, but I just found the source of the error: if playersTouched[player.UserId] then playersTouched[player.UserId] = nil. I commented it out, then made it print the contents of the table after it had added me, it printed nothing. Could you help me with this?

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