Attempting to assign money to a user with a certain string in their steam name Glua

75 Views Asked by At

I'm making a reward based system for having a username in a steam name and I have got this far so far

local XPTimer = 0

local XPTimer = CurTime() + 10

if(XPTimer <= CurTime()) then
    if string.find("SERVERNAME", ply:SteamName()) then
            starwarsrp.ply:AddMoney(500)
                            starwarsrp.notify(ply, 3, 4, "You were awarded £500 for being part of SERVERNAME team!")

        end
    else
        Msg("didnt work")
end
XPTimer = CurTime() + 10

I am receiving the "else" message in the console "didn't work" and the timer doesn't seem to be working. Is there a thing I am doing wrong here. I appreciate the feedback!

1

There are 1 best solutions below

11
On

Judging by string.find("SERVERNAME", ply:SteamName()), you are trying to find SteamName value in "SERVERNAME" string, which is likely to fail all the time, unless your Steam name happens to be a sub-string of SERVERNAME. You were probably thinking about getting the value of SERVERNAME environmental variable and for this you need to use os.getenv("SERVERNAME"), so something like string.find(os.getenv("SERVERNAME") or "", ply:SteamName()) may work better (you need or "" as os.getenv may return nil when SERVERNAME is not set and string.find will throw an error on the nil passed to it).