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

Match string from data store?

Asked by 4 years ago
Edited 4 years ago

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
0
Also did you add a Part.Touched:Connect(OnTouched) at the end? OhManXDXD 445 — 4y

1 answer

Log in to vote
0
Answered by
OhManXDXD 445 Moderation Voter
4 years ago
Edited 4 years ago

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
0
Thank you! Works great lucky_thirteen13 -1 — 4y
Ad

Answer this question