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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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!

0
Thank you so much! MusicalDisplay 173 — 6y
Ad

Answer this question