1

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!

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
Owen
  • 129
  • 1
  • 4

1 Answers1

0

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).

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • Probably, it is `someTable.SERVERNAME` – Egor Skriptunoff Sep 06 '17 at 18:38
  • I tried that and It still doesnt work. I get the error `attempt to call field 'getenv'` – Owen Sep 06 '17 at 19:28
  • It means that `os` table doesn't have `getenv` field (as you are probably running in a sandbox environment). Are you missing some table before `SERVERNAME` as Egor suggested? – Paul Kulchenko Sep 06 '17 at 23:04
  • how would I implement `someTable.SERVERNAME` would it be like this if `string.find(os.getenv(someTable.SERVERNAME) or "", ply:SteamName()) then` – Owen Sep 07 '17 at 15:30
  • No, Egor and I thought that maybe you have SERVERNAME as a field in one of the tables. Where are you trying to check for `ply:SteamName()`? Where do you expect `SERVERNAME` value to come from? – Paul Kulchenko Sep 07 '17 at 16:14
  • I'll be honest, I'm not quite sure what you mean. Sorry I'm not very good at this – Owen Sep 07 '17 at 18:32
  • Why are you checking `"SERVERNAME"` string? Where do you get the reference from? – Paul Kulchenko Sep 07 '17 at 18:40
  • @Owen - Where did you see an example of code which uses `SERVERNAME`? – Egor Skriptunoff Sep 08 '17 at 07:23
  • the "Servername" is a string, it will have the name of my server in there to compare – Owen Sep 08 '17 at 15:53
  • Then try with `string.find(SERVERNAME, ply:SteamName())` if it's a variable, but you need to make sure it's spelled *exactly* as needs to be (whether it's `Servername` or `SERVERNAME` or something else). – Paul Kulchenko Sep 08 '17 at 16:15
  • that's what I had originally up above but it didn't work – Owen Sep 10 '17 at 11:12