How to Make Player Change Clock Time with Chatted Event

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local message = string.lower(msg)
		if message == string.lower(";Time ") then
			-- get the last number at the end of ;Time and set lighting.ClockTime to it
		end

	end)
end)

i want to get the last number at the end of “;time” and then set lighting.clocktime to it

1 Like

You can use string.split to convert your message into an array of strings and see if the player specified a number to set the time to.

local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")

local timeCommand = ";time"

Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(message)
		local splitString = string.split(message, " ")
		
		local command = splitString[1]
		local clockTime = tonumber(splitString[2])

		if command:lower() == timeCommand:lower() and clockTime then
			Lighting.ClockTime = clockTime
		end
	end)

end)
1 Like

Use string.split to get the arguments.

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local message = string.split(msg," ")
		if message[1] == string.lower(";Time") then
			game:GetService(" Lighting").ClockTime = message[2]
		end

	end)
end)

Wrote this on mobile without testing, may have errors.

Edit: Fixed quotation marks

1 Like

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