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

How to manipulate strings for admin commands?

So what i want my code to do is when i chat ';level bub 100' it changes my level to 100. However im having troubles getting the values from the string when the player chats.

--Prefix being ';'
if msg:lower():sub(1,#Prefix + 6) == Prefix:lower() .. "level " then
	print("Level Command")
	--Check if a player with the name following (or part of the name) exists
	
	local levels = msg:lower():sub(7):find(" ") + 6
	local name = msg:lower():sub(#Prefix + (levels - 1) )
	
	print("levels ".. levels) --Prints 7(?)
	print("name ".. name) -- Prints ''bub 100'
	
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Name:sub(1, #name):lower() == name then
			v.leaderstats.Lvl.Value = Levels
		end
	end
	
end

Ive been playing around a while with this; but fairly new to this area. Any helps is much appreicated; Thanks, Bubs.

1 answer

Sorry if it doesn't work with the functions you used, I just wrote this off of the top of my head.

local player = game.Players.LocalPlayer

player.Chatted:connect(function(msg)
	if msg:lower():sub(1,6) == "level/" then
		player.leaderstats.Level = player.leaderstats.Level + msg:sub(7,#msg)
	end
end)

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