How do i remove a bit of a message when you say it

So im making a command called !addstat, it adds a stat to the leaderboard and currently right now it works if you type !addstat, but the thing is i dont want it to include the !addstat in the leaderstat value

So like if i type “!addstat coins”
the stats name will be “!addstat coins”
but i want the stats name to be “coins”

I havent seen things about this issue

my code right now

game.Players.PlayerAdded:Connect(function(player)
	local chat = player.Chatted:Connect(function(message)
if string.sub(message, 1, 9) == "!addstat " then
			local leaderstats = player:FindFirstChild("leaderstats")
			local newValue = Instance.new("IntValue")
		newValue.Parent = leaderstats
			newValue.Name = message
		end
	end)
end)

You can use the split() function to split the message.

local splitMessage = message:Split(" ")
print(splitMessage[2])

i didnt know where to put it but then i found somewhere and it told me how to do it

so this is the script now

game.Players.PlayerAdded:Connect(function(player)
	local chat = player.Chatted:Connect(function(message)
		if string.sub(message, 1, 9) == "!addstat " then
			local leaderstats = player:FindFirstChild("leaderstats")
			local newValue = Instance.new("IntValue")
			newValue.Parent = leaderstats
			local currentString = message
			local newString = string.sub(currentString,10,#currentString)
			newValue.Name = newString
		end
	end)
end)
1 Like

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