So basically whenever someone guesses the build, it's supposed to destroy it, it does but if no-one can guess it within 60 seconds it's supposed to destroy it. When I guess it correctly multiple times and then I wait it out, it waits 20 seconds instead of 60. 46
When someone guesses it, at line 46 it's supposed to make it so it sets the timer value to Reset and then it triggers in another script.
Main script:
-- Variables --
local rs = game:GetService("ReplicatedStorage")
local serverstorage = game:GetService("ServerStorage")
local builds = serverstorage:WaitForChild("Builds")
local status = rs:WaitForChild("Status")
local intermissionlength = 5
local minplayers = 1
-- Script --
while true do
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
msg = string.lower(msg)
if msg == ClonedBuild.Name then
player.leaderstats.Guesses.Value = player.leaderstats.Guesses.Value + 1
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 10
ClonedBuild:Destroy()
status.Value = player.Name.. " correctly guessed the build. It was ".. ClonedBuild.name.. "!"
end
end)
end)
status.Value = "Waiting for at least "..minplayers .. " players."
repeat wait() until game.Players.NumPlayers >= minplayers
status.Value = "Intermission..."
wait(intermissionlength)
AvailableBuilds = builds:GetChildren()
ClonedBuild = AvailableBuilds[math.random(1,#AvailableBuilds)]
status.Value = "Guess The Build!"
rs:WaitForChild("Timer").Value = "Run"
ClonedBuild = ClonedBuild:Clone()
ClonedBuild.Parent = workspace
repeat wait() until game.Workspace:FindFirstChild(ClonedBuild.Name) == nil or rs:WaitForChild("Timer").Value == "Done"
rs:WaitForChild("Timer").Value = "Reset"
local b = game.Workspace:FindFirstChild(ClonedBuild.Name)
if b ~= nil then
workspace[ClonedBuild.Name]:Destroy()
ClonedBuild = nil
status.Value = "No-one guessed the build in time!"
wait(3)
else
ClonedBuild = nil
wait(3)
end
end
Timer script:
local rs = game:GetService('ReplicatedStorage')
local timerv = rs:WaitForChild("Timer")
local roundtime = 60
timerv.Changed:Connect(function()
if timerv.Value == "Run" then
wait(roundtime)
timerv.Value = "Done"
elseif timerv.Value == "Reset" then
print("Reset")
end
end)

2 comments
You shouldn't have PlayerAdded and a Chatted event inside of the while loop as you will make more connections each time the loop goes again.
That won't fix the issue though.