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

What would I do if I wanted to make a keydown function work for only the names of people on a table?

Asked by 10 years ago

This is in a localscript with a ScreenGUI as the parent and I'm trying to script it so when you press "e" a GUI will show only if you're a 'VIP'.

So far, I have a normal keydown function, but I don't know where I could put a line of script so that it only works for the people included in the VIP table.

plr=game.Players.LocalPlayer
local mouse=plr:GetMouse()
sp=script.Parent

VIP={"Devotional","BestFriend"}

--[[for i=1,#VIP do
    if string.lower(plr.Name)==string.lower(VIP[i]) then]] --I think I should use this, I'm just not sure where to insert it in the following function

mouse.KeyDown:connect(function(key)
    if key=="e" then
        if sp.VIPscreen.Visible==false then
            sp.VIPscreen.Visible=true
        else
            sp.VIPscreen.Visible=not sp.VIPscreen.Visible
        end
    end
end)        

Thanks in advance!

1 answer

Log in to vote
1
Answered by 10 years ago
for k, v in pairs(VIP) do
     if string.lower(plr.Name)==string.lower(v) then
            mouse.KeyDown:connect(function(key)
             if key=="e" then
                    if sp.VIPscreen.Visible==false then
                        sp.VIPscreen.Visible=true
                    else
                        sp.VIPscreen.Visible= not sp.VIPscreen.Visible
                    end
            end
        end)  
    end
end

Try doing that. Inside your check for the key to be an e, you most likely could just do: sp.VIPscreen.Visible = not sp.VIPscreen.Visible instead of what you had it as.

Ad

Answer this question