I need help with a script

I’ve been trying to make a system where someone gets puts inside of a jail cell for 5 seconds, and whenever someone types in jail in the chat, it increases the timer by 1 second.

I’ve been trying to achieve this but to no success, can somebody please help me what I got to script this system? Thank you for reading.

Here’s the script so far:

local player = game.Players.LocalPlayer
local Message = "jail"
local jailTime = game.ReplicatedStorage:WaitForChild("jailTime")
local bool = false
local totalTime = game.ReplicatedStorage:WaitForChild("Time")
totalTime.Value = 5

jailTime.OnClientEvent:Connect(function(boolean)
	if boolean == true then
		bool = boolean
	end
	while bool == true do
		task.wait(totalTime.Value)
	end
end)

player.Chatted:Connect(function(message)
	if bool == true then
		if string.find(string.lower(message), string.lower(Message)) then
			totalTime.Value += 1
		end
	end
end)

I removed all my failed codes.

I think you get the point, sorry if I deleted something you need

jailTime.OnClientEvent:Connect(function(boolean)
	if boolean then
		repeat
			task.wait(1)
			totalTime.Value-=1
		until not totalTime or totalTime.Value<=0
	end
end)
1 Like

This looks like a local script, so will only affect clients individually. See also @3YbuKtOp 's post.

1 Like

is it a bad thing if i put it on a local script? Because I have like a game loop in my server script and if i put a wait in there then the game loop would have to wait until it reaches 0

The total time value will be local to each client because that is all the player.chatted event connects to. I might have misunderstood your setup but you would probably need to send this value to the server loop no?
Nevermind I did misunderstand!

1 Like

Theoretically, you can make a local script and this will not be a problem. But there are exploiters who can bypass your jail

1 Like

Can he do .Chatted locally, or am I wrong?

1 Like

Yes i can do chatted locally I have teste. And the script does work for me so thank you!

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