String.split doesnt return 6th string

I’m trying to get the 6th args that were in string.split, but instead it returns nil.

local Cache = script.Parent.Parent:FindFirstChild("cache")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local SavedFolder = LocalPlayer:FindFirstChild("carsSaved")
--local ProUI = require(script.Parent.Parent.Parent.MainModule)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Viewport = script.Parent

local components = {
	label = Viewport.Parent:FindFirstChild("carName"),
	decal = Viewport:FindFirstChild("decalPreview"),
	sound = Viewport:FindFirstChildOfClass("Sound"),
	license = Viewport:FindFirstChild("licensePreview"),
	soundButton = Viewport:FindFirstChild("soundPause"),
	left = Viewport:FindFirstChild("controlB"),
	right = Viewport:FindFirstChild("controlA")
}

local Format = "name~carColor~logoColor~decal~license~audio"
local Page = 1

local function viewCar(carModel)
	local currentPage = SavedFolder:FindFirstChild("Slot"..Page)
	
	if not currentPage.Value == Format then -- Checks if the value is different
		if Viewport:FindFirstChildOfClass("Model") then
			Viewport:FindFirstChildOfClass("Model").Parent = Cache
		end
		
		carModel.Parent = Viewport
		
		local slotData = string.split(currentPage.Value, "~") -- Splits the value
		
		local name = slotData[1]
		local carcolor = slotData[2]
		local logocolor = slotData[3]
		local decal = slotData[4]
		local license = slotData[5]
		local audio = slotData[6]
		
		warn(name,
			carcolor,
			logocolor,
			decal,
			license,
			audio
		)
		
		components.label.Text = name
		components.decal.Image = decal
		components.license.Text = license
		components.sound.SoundId = audio
		
		local round = math.round
		
		local splitColors = string.split(carcolor,",")
		local r, g, b = round(splitColors[1]*255), round(splitColors[2]*255), round(splitColors[3]*255) 
		
		for _, v in pairs(carModel.Model:GetChildren()) do
			if v.Name == "canChange" then
				v.Color = Color3.fromRGB(r,g,b)
			end
		end
		
		local splitColors2 = string.split(logocolor,",")
		local q, b, c = round(splitColors2[1]*255), round(splitColors2[2]*255), round(splitColors2[3]*255) 
		
		carModel.log.Union.Color = Color3.fromRGB(q,b,c)
		
	else
		
		if Viewport:FindFirstChildOfClass("Model") then
			Viewport:FindFirstChildOfClass("Model").Parent = Cache
		end
		
		local a=Instance.new"TextLabel"
		a.Size=UDim2.new(0.521, 0,0.141, 0)
		a.BackgroundTransparency=1
		a.Position=UDim2.new(0.2475411,0,0.5461732,0)
		a.BackgroundColor3=Color3.fromRGB(255,255,255)
		a.FontSize=5
		a.TextSize=14
		a.RichText=true
		a.TextColor3=Color3.fromRGB(255,255,255)
		a.Text="Oh <i>look</i>, an empty <b>slot!</b>"
		a.TextWrap=true
		a.Font=35
		a.TextWrapped=true
		a.TextScaled=true
		a.ZIndex = 2
		local b=Instance.new"ImageLabel"
		b.Size=UDim2.new(0.229, 0,1.483, 0)
		b.BackgroundTransparency=1
		b.Position=UDim2.new(0.3856969,0,-1.3461798,0)
		b.BackgroundColor3=Color3.fromRGB(255,255,255)
		b.Image="rbxassetid://8635740892"
		b.Parent=a
		b.ZIndex = 2
		a.Parent=Viewport
	end
end

viewCar(Cache:FindFirstChild("Vroom"..Page))

local function updateControls()
	if Page == 1 then
		components.left.Visible = false
	end
	
	if Page >= 2 then
		components.left.Visible = true
	end
	
	if Page == 5 then
		components.right.Visible = false
	end
end

local function expand()
	Page = Page + 1
	
	updateControls()
	viewCar(Cache:FindFirstChild("Vroom"..Page))
end

local function decrease()
	Page = Page - 1

	updateControls()
	viewCar(Cache:FindFirstChild("Vroom"..Page))
end

components.right.MouseButton1Click:Connect(expand)
components.left.MouseButton1Click:Connect(decrease)
1 Like

If you print:

print(string.split("name~carColor~logoColor~decal~license~audio","~"))

image
You get the correct output. When you split currentPage.Value, it probably doesn’t have a 6th argument, try printing the Value and see what it is!

1 Like

try write

local slotData = tostring(currentPage.Value):split("~") instead.

1 Like

The value and the format has the same string, but for the StringValue, the string prints nil for the 6th string

1 Like

It seems that it now works after I reset my datastore.

1 Like