Hi, I’m looking for help on shortening and improving this script, any help is greatly appreciated.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DoorMessage = ReplicatedStorage.Events:WaitForChild("DoorMessage")
local TimerSpeed = ReplicatedStorage.Values:WaitForChild("TimerSpeed")
local MultiplierVisible = ReplicatedStorage.Values:WaitForChild("MultiplierVisible")
local Multiplies = ReplicatedStorage.Values:WaitForChild("Multiplies")
local Minutes = ReplicatedStorage.Values:WaitForChild("Minutes")
local Seconds = ReplicatedStorage.Values:WaitForChild("Seconds")
local Winners = {}
script.Parent.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if not Hit.Parent:FindFirstChild("Humanoid") then return end
if not Player then return end
if table.find(Winners, Player.UserId) then return end
table.insert(Winners, Player.UserId)
TimerSpeed.Value = TimerSpeed.Value / 2
DoorMessage:FireAllClients(Player)
MultiplierVisible.Value = true
Multiplies.Value = Multiplies.Value * 2
end)
Minutes.Changed:Connect(function()
if Minutes.Value == 2 and Seconds.Value == 0 then
if not Winners then return end
for _, id in pairs(Winners) do
local Player = game:GetService("Players"):GetPlayerByUserId(id)
if not Player then continue end
if not Player:WaitForChild("leaderstats") then continue end
if not Player.leaderstats:WaitForChild("🍬 Candy") then continue end
Player.leaderstats:WaitForChild("🍬 Candy").Value = Player.leaderstats:WaitForChild("🍬 Candy").Value + 80
if Player.DoubleCandy.Value == true then
Player.leaderstats:WaitForChild("🍬 Candy").Value = Player.leaderstats:WaitForChild("🍬 Candy").Value + 80
end
end
Winners = {}
end
end)