Need help with splitting AnimationEvent parameter into numbers

If the topic name wasn’t clear, I want to separate my AnimationEvent parameter into numbers.

  • What my parameter (string) looks like: "Brightness:0.5 Contrast:-0.1 Saturation:0"

  • What I want it to return: {0.5, -0.1, 0}

  • What it returns when separating it: {"Brightness", "0.5 Contrast", "-0.1 Saturation", "0"}

  • What I used to separate it (command bar script):

local Parameter = "Brightness:0.5 Contrast:-0.1 Saturation:0" local Split = Parameter:split(":") print(Split)

Any help is appreciated.

A little function might help you with this.

function splitString(aString)
	local result = {} --store the values here in order

	for label, value in aString:gmatch("([^%s:]+):(-?%d+%.?%d*)") do --separate what we want from aString
		table.insert(result, tonumber(value)) --insert the values we got inside the table
	end

	return result --return the baked cake
end

-- example:
local yourString = "Brightness:0.5 Contrast:-0.1 Saturation:0"
local splitResult = splitString(yourString)

for _, value in ipairs(splitResult) do
	print(value)
end

This is helpful.
Strings | Documentation - Roblox Creator Hub

2 Likes

It works perfectly! Thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.