Hi I am trying to get a string that has been stored and when a part is touched it checks if the string matches. when i touch the part nothing happens, what am i doing wrong?
01 | function OnTouched(Part) |
02 | local str = "" |
03 | local player = game.Players:GetPlayerFromCharacter(Part.Parent) |
04 | if player then |
05 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
06 | if leaderstats then |
07 | str = leaderstats.Rank.Value |
08 | if string.match(str, "Rec" ) then |
09 | print ( "Works" ) |
10 | else |
11 | print ( "doesnt work" ) |
12 | end |
13 | end |
14 | end |
15 | end |
Sorry, I saw the question wrong. Try first defining str as just leaderstats.Rank, then finding the value when using string.match
01 | function OnTouched(Part) |
02 | local str = "" |
03 | local player = game.Players:GetPlayerFromCharacter(Part.Parent) |
04 | if player then |
05 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
06 | if leaderstats then |
07 | str = leaderstats:WaitForChild( "Rank" ) -- Waits for the rank to load |
08 | if string.match(str.Value, "Rec" ) then |
09 | print ( "Works" ) |
10 | else |
11 | print ( "doesnt work" ) |
12 | end |
13 | end |
14 | end |
15 | end |