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?

01function 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
15end
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

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

Answer this question