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?
function OnTouched(Part) local str = "" local player = game.Players:GetPlayerFromCharacter(Part.Parent) if player then local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then str = leaderstats.Rank.Value if string.match(str, "Rec") then print("Works") else print("doesnt work") end end end end
Sorry, I saw the question wrong. Try first defining str as just leaderstats.Rank, then finding the value when using string.match
function OnTouched(Part) local str = "" local player = game.Players:GetPlayerFromCharacter(Part.Parent) if player then local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then str = leaderstats:WaitForChild("Rank") -- Waits for the rank to load if string.match(str.Value, "Rec") then print("Works") else print("doesnt work") end end end end