Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Match string from data store?

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

1 comment

0

Also did you add a Part.Touched:Connect(OnTouched) at the end?

1 answer

✓ Accepted answer

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

1 comment

0

Thank you! Works great

This discussion is preserved as it was. New answers, comments, and votes are closed.