-- Script: ServerScriptService > BoostServer -- Lesson 11 replaces this script's contents; do not run both versions. local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Config = { RequiredCoins = 3, Radius = 12, Speed = 28, Duration = 5, Cooldown = 20, RequestInterval = 0.5, } local station = workspace:WaitForChild("BoostStation", 10) assert(station and station:IsA("BasePart"), "Create Workspace.BoostStation Part") assert(not ReplicatedStorage:FindFirstChild("BoostRemotes"), "Run only one BoostServer") local remotes = Instance.new("Folder") remotes.Name = "BoostRemotes" local request = Instance.new("RemoteEvent") request.Name = "RequestBoost" request.Parent = remotes local feedback = Instance.new("RemoteEvent") feedback.Name = "BoostFeedback" feedback.Parent = remotes remotes.Parent = ReplicatedStorage local lastRequest = {} local nextAllowed = {} local active = {} local function reply(player, requestId, ok, message) feedback:FireClient(player, requestId, ok, message) end request.OnServerEvent:Connect(function(player, action, requestId) local now = os.clock() if now - (lastRequest[player] or -math.huge) < Config.RequestInterval then return -- Do not multiply a flood by sending a reply for every rejected request. end lastRequest[player] = now if typeof(requestId) ~= "number" or requestId % 1 ~= 0 or requestId < 1 or requestId > 1000000000 then return -- Correlation metadata must also be bounded and well-formed. end if typeof(action) ~= "string" or action ~= "speed" then reply(player, requestId, false, "Unknown request") return end local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") local root = character and character:FindFirstChild("HumanoidRootPart") if not humanoid or humanoid.Health <= 0 or not root or not root:IsA("BasePart") then reply(player, requestId, false, "Respawn before requesting a boost") return end local distance = (root.Position - station.Position).Magnitude if not (distance <= Config.Radius) then -- Also rejects NaN distances. reply(player, requestId, false, "Move closer to the green boost station") return end local leaderstats = player:FindFirstChild("leaderstats") local coins = leaderstats and leaderstats:FindFirstChild("Coins") if not coins or not coins:IsA("IntValue") or coins.Value < Config.RequiredCoins then reply(player, requestId, false, "Collect " .. Config.RequiredCoins .. " coins first") return end local remaining = (nextAllowed[player] or 0) - now if remaining > 0 or active[player] then reply(player, requestId, false, "Boost cooling down; try again shortly") return end -- No yielding between final validation and committing the state change. nextAllowed[player] = now + Config.Cooldown local token = {} active[player] = token local previousSpeed = humanoid.WalkSpeed humanoid.WalkSpeed = Config.Speed reply(player, requestId, true, "Boost active for " .. Config.Duration .. " seconds") task.delay(Config.Duration, function() if active[player] ~= token then return end active[player] = nil if player.Character == character and humanoid.Parent and humanoid.WalkSpeed == Config.Speed then humanoid.WalkSpeed = previousSpeed end if player.Parent == Players then reply(player, requestId, true, "Boost ended; wait for the cooldown before reusing") end end) end) Players.PlayerRemoving:Connect(function(player) lastRequest[player] = nil nextAllowed[player] = nil active[player] = nil end)