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

Can you track somebody's name in a touch function?

I understand that you can find the players name through the parameters. Like this:

script.Parent.Touched:connect(function(hit)
	print(hit.Parent.Name)
end)

But can you find the player's name, store it in a table (not using data store), and reference(find) it when needed?

I have this:

local PlayerTable = {}

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- for checking purposes
		if --[[DOESN'T FIND NAME IN TABLE--]]  then	
			table.insert(PlayerTable,hit.Parent.Name)
		end	
	end
end)

If there are any wiki pages on this please send the links

1 answer

✓ Accepted answer

Ohhhhhhh, are you're trying to maybe make a debounce for specific players? I guess I'll just answer your question first:


You can store a string into a table and reference it easily like this:

local tb = {}

tb[string] = true

if tb[string] then
	-- this will get ran
end

More info


Adding this to your script:

local PlayerTable = {}

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- for checking purposes
        if not PlayerTable[hit.Parent.Name] then 
            PlayerTable[hit.Parent.Name] = true
        end 
    end
end)

That will make it so the code will only run for players once. I think this is what you wanted.


Good Luck!

1 comment

0

Thank you so much!

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