Issues with Chat Commands

  1. What do you want to achieve? I’m trying to create a chat system in which when a player who has the right rank in a certain group writes !shiftstart, a “stopwatch” will start for all the workers of the group (those workers ranks are >=3) and if the player who said !shiftstart says !shiftend if a worker has been working for more than 8 minutes then they’ll receive a notification and the they’ll be able to end their shift.

  2. What is the issue? They are lots of things wrong with my code. 1, the for loop isn’t running. And 2, not sure how to do the timer/stopwatch. Anyways, here’s my code.

game.Players.PlayerAdded:Connect(function(Player)
	
	if Player:GetRankInGroup(12556758) >= 3 then
		local WorkerValue = game.ReplicatedStorage.Values.IsWorker
		WorkerValue.Value = true
		WorkerValue.Parent = Player
	end
	Player.Chatted:Connect(function(message)
		local AdminWhoUsedCMD = game.ReplicatedStorage.Values.AdminWhoUsedCMD
		if string.find(message, "!shiftstart") then
			if Player:GetRankInGroup(12556758) >= 8 then
				
			AdminWhoUsedCMD.Value = Player.Name
						
			local GrabWorkers = game.Players:GetPlayers()
				
			for i, v in pairs(GrabWorkers) do
					local Worker = v:WaitForChild("IsWorker").Value

					if Worker == true then
						local MinutesEvent = game.ReplicatedStorage.Events.MinutesEvent
						local MinutesValue = script.Minutes:Clone()
						MinutesValue.Parent = v
						
						local SecondsValue = script.Seconds:Clone()
						SecondsValue.Parent = v
						
						while true do
							wait(1)
							local seconds = 0
							local minutes = 0

							seconds = seconds +1
							
							if seconds >= 60 then
								minutes = minutes +1
								seconds = 0
							end
							
							MinutesValue.Value = minutes

							SecondsValue.Value = seconds
						end
				end
		end
end
			
			
		elseif string.find(message, "!shiftend") then
			local MinutesWorked = Player:FindFirstChild("Minutes")
			if Player:GetRankInGroup(12556758) >= 8 then
				local GrabWorkers = game.Players:GetPlayers()
				
				for _, v in pairs(GrabWorkers) do
					local Worker = v:WaitForChild("IsWorker").Value
					
					if Worker == true then
						if MinutesWorked.Value > 8 then
							local ShiftEndGui = script.ShiftEnd
							ShiftEndGui.Parent = Player.PlayerGui

							ShiftEndGui.ShiftEndFrame:TweenPosition(UDim2.new(0.314, 0,0.323, 0), "In", "Quint")
							ShiftEndGui.ShiftEndFrame.Handler.Disabled = false
						else
							print(Worker.Parent.Name.." has not worked 8 minutes, in order for them to end the shift, they need to work for "..8 - MinutesWorked.Value.." more minutes.")
						end
					end
				end
			end
		end
	end)
end)
  1. What solutions have you tried so far? I haven’t seen anything like this on the DevForum so no, I haven’t found any solutions for this. But, if you know a solution, please let me know!

I haven’t tested it but this might work.

local Prefix = "!"

local Time = 0
local Minimum = 480 -- 8 minutes in seconds

game.Players.PlayerAdded:Connect(function(Player)

	if Player:GetRankInGroup(12556758) >= 3 then
		local WorkerValue = game.ReplicatedStorage.Values.IsWorker
		WorkerValue.Value = true
		WorkerValue.Parent = Player
	end
	
	Player.Chatted:Connect(function(Chat)
		local AdminWhoUsedCMD = game.ReplicatedStorage.Values.AdminWhoUsedCMD
		local Message = Chat:split(" ")
		
		if string.lower(Message[1]) == Prefix.."shiftstart" then
			if Player:GetRankInGroup(12556758) >= 8 then
				AdminWhoUsedCMD.Value = Player.Name
				for i, v in pairs(game.Players:GetPlayers()) do
					local Worker = v:FindFirstShild("IsWorker").Value
					if Worker then
						repeat wait(1)
							Time += 1
						until Time >= Minimum
						-- notification
					end
				end
			end
		elseif string.lower(Message[1]) == Prefix.."shiftend" then
			if Player:GetRankInGroup(12556758) >= 8 then
				if Time >= Minimum then
					-- do stuff
				end
			end
		end
	end)
end)