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 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)
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!