hey so i have a commission for roblox and its just bug fixing so lets do it!
basically first bug is the game is a kill players and steal their time and when the dev killed a player with 84,039 time it didnt get transfered to the player that killed them which its supposed to.
basically whenever a player kills another player they steal their time.
the thing is i dont know the script that is causing this so im gonna find it quickly.
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Configuration
Players.CharacterAutoLoads = true -- Let Roblox handle respawns fully
local SAFE_ZONE_PART_NAME = "SafeZone"
local TIME_GAIN_RATE = 1
local DATASTORE_NAME = "PlayerStats_v3"
local MAX_XP_PER_SECOND = 3000
local MAX_TIME = 100000000
local XPBoostPerLevel = 4
-- Data
local playerDataStore = DataStoreService:GetDataStore(DATASTORE_NAME)
local playerStates = {}
local recentKills = {}
-- Remotes
local remoteXP = ReplicatedStorage:WaitForChild("UpdateXPDetails", 5)
local killLogEvent = ReplicatedStorage:FindFirstChild("KillLogEvent")
if not killLogEvent then
killLogEvent = Instance.new("RemoteEvent", ReplicatedStorage)
killLogEvent.Name = "KillLogEvent"
end
function _G.awardXP(player, amount, sourceText)
local playerData = player:FindFirstChild("PlayerData")
local stats = player:FindFirstChild("leaderstats")
if not playerData or not stats then return end
code
local xp = playerData:FindFirstChild("XP")
local level = stats:FindFirstChild("Level")
if not xp or not level then return end
xp.Value += amount
local success, err = pcall(function()
local OrderedStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_XP")
local sortKey = (level.Value * 1_000_000) + xp.Value
OrderedStore:SetAsync(tostring(player.UserId), sortKey)
end)
if not success then
warn("Failed to update leaderboard XP for", player.Name, err)
end
if remoteXP then
local state = playerStates[player.UserId]
if state then
state.xpCounters = state.xpCounters or {}
sourceText = sourceText or "XP"
state.xpCounters[sourceText] = (state.xpCounters[sourceText] or 0) + 1
remoteXP:FireClient(player, sourceText, state.xpCounters[sourceText], amount)
end
end
local requiredXP = 100 * (level.Value ^ 2)
while xp.Value >= requiredXP do
xp.Value -= requiredXP
level.Value += 1
requiredXP = 100 * (level.Value ^ 2)
end
end
local function isInSafeZone(character)
local hrp = character:FindFirstChild("HumanoidRootPart")
if not hrp then return false end
for _, zone in ipairs(workspace:GetDescendants()) do
if zone:IsA("BasePart") and zone.Name == SAFE_ZONE_PART_NAME then
local rel = zone.CFrame:PointToObjectSpace(hrp.Position)
local half = zone.Size / 2
if math.abs(rel.X) <= half.X and math.abs(rel.Y) <= half.Y and math.abs(rel.Z) <= half.Z then
return true
end
end
end
return false
end
local function savePlayerStats(player)
local stats = player:FindFirstChild("leaderstats")
local pdata = player:FindFirstChild("PlayerData")
if not stats or not pdata then return end
code
local record = {
Time = stats.Time.Value,
Kills = stats.Kills.Value,
Level = stats.Level.Value,
BestTime = stats.BestTime.Value,
XP = pdata:FindFirstChild("XP") and pdata.XP.Value or 0,
Streak = stats.Streak.Value
}
local success, err = pcall(function()
playerDataStore:SetAsync(tostring(player.UserId), record)
end)
if not success then
warn("Failed to save data for", player.Name, err)
end
end
local function updateBestTime(player)
local stats = player:FindFirstChild("leaderstats")
if not stats then return end
local t = stats:FindFirstChild("Time")
local bt = stats:FindFirstChild("BestTime")
if t and bt and t.Value > bt.Value then
bt.Value = t.Value
end
end
local function sendKillLogToAll(messageData)
task.spawn(function()
local ok, err = pcall(function()
for _, plr in ipairs(Players:GetPlayers()) do
killLogEvent:FireClient(plr, messageData)
end
end)
if not ok then
warn("Kill log send failed:", err)
end
end)
end
local function handleDeath(player, humanoid)
local stats = player:FindFirstChild("leaderstats")
if not stats then return end
updateBestTime(player)
savePlayerStats(player)
code
local killer = humanoid:FindFirstChild("creator") and humanoid.creator.Value
local state = playerStates[player.UserId]
if state then
state.canGainTime = false
end
if killer and killer:IsA("Player") and killer ~= player then
local kSafe = isInSafeZone(killer.Character)
local vSafe = isInSafeZone(player.Character)
if kSafe or (not kSafe and not vSafe) then
local id = ("%d_%d_%d"):format(player.UserId, killer.UserId, os.time())
if not recentKills[id] then
recentKills[id] = true
task.delay(10, function() recentKills[id] = nil end)
local kstats = killer:FindFirstChild("leaderstats")
if kstats then
local stolenTime = stats.Time.Value
kstats.Time.Value += stolenTime
stats.Time.Value = 0
kstats.Kills.Value += 1
kstats.Level.Value = math.floor(kstats.Kills.Value / 10) + 1
kstats.Streak.Value += 1
stats.Streak.Value = 0
updateBestTime(killer)
savePlayerStats(killer)
_G.awardXP(killer, 100, "Kill")
local dist = 0
local hrpK = killer.Character:FindFirstChild("HumanoidRootPart")
local hrpV = player.Character:FindFirstChild("HumanoidRootPart")
if hrpK and hrpV then
dist = math.floor((hrpK.Position - hrpV.Position).Magnitude * 10) / 10
end
sendKillLogToAll({
KillerName = killer.Name,
VictimName = player.Name,
TimeNow = kstats.Time.Value,
StolenTime = stolenTime,
Distance = dist,
ToolName = (killer.Character:FindFirstChildOfClass("Tool") or {}).Name or "Fists",
Streak = kstats.Streak.Value
})
end
else
stats.Time.Value = 0
end
else
stats.Time.Value = 0
if not vSafe then
sendKillLogToAll({
KillerName = nil,
VictimName = player.Name,
TimeNow = stats.Time.Value,
StolenTime = 0,
Distance = 0,
ToolName = "Died"
})
end
end
elseif not isInSafeZone(player.Character) then
local lost = stats.Time.Value
stats.Time.Value = 0
sendKillLogToAll({
KillerName = nil,
VictimName = player.Name,
TimeNow = lost,
StolenTime = 0,
Distance = 0,
ToolName = "Died"
})
end
end
local function onCharacterAdded(player, character)
local state = playerStates[player.UserId]
if not state then return end
code
state.canGainTime = true
state.lastTimeUpdate = os.clock()
if not isInSafeZone(character) then
player.leaderstats.Time.Value = 0
end
local humanoid = character:WaitForChild("Humanoid", 10)
if not humanoid then
warn("No Humanoid for", player.Name)
return
end
humanoid.Died:Connect(function()
state.canGainTime = false
pcall(handleDeath, player, humanoid)
-- No forced respawn, let Roblox handle it
end)
end
local function setupPlayer(player)
local stats = Instance.new("Folder", player)
stats.Name = "leaderstats"
for name, val in pairs({Time=0, Kills=0, Level=1, BestTime=0, Streak=0}) do
local st = Instance.new("IntValue", stats)
st.Name = name
st.Value = val
end
code
local pdata = Instance.new("Folder", player)
pdata.Name = "PlayerData"
local xp = Instance.new("NumberValue", pdata)
xp.Name = "XP"
local success, data = pcall(function()
return playerDataStore:GetAsync(tostring(player.UserId))
end)
if success and data then
local ls = player.leaderstats
ls.Time.Value = data.Time or 0
ls.Kills.Value = data.Kills or 0
ls.Level.Value = data.Level or 1
ls.BestTime.Value = data.BestTime or 0
xp.Value = data.XP or 0
ls.Streak.Value = data.Streak or 0
end
playerStates[player.UserId] = {
canGainTime = false,
lastTimeUpdate = os.clock(),
lastXPUpdate = 0,
xpCounters = {},
lastSafeState = true,
}
player.CharacterAdded:Connect(function(character)
onCharacterAdded(player, character)
end)
end
RunService.Heartbeat:Connect(function()
local now = os.clock()
for _, player in ipairs(Players:GetPlayers()) do
local state = playerStates[player.UserId]
local stats = player:FindFirstChild("leaderstats")
local char = player.Character
local humanoid = char and char:FindFirstChild("Humanoid")
if state and stats and humanoid and humanoid.Health > 0 and char:FindFirstChild("HumanoidRootPart") then
local inSafe = isInSafeZone(char)
if inSafe and not state.lastSafeState then
state.xpCounters = {}
end
state.lastSafeState = inSafe
code
if not inSafe then
state.canGainTime = true
if now - state.lastTimeUpdate >= 1 then
stats.Time.Value += TIME_GAIN_RATE
state.lastTimeUpdate = now
if not state.lastXPUpdate or now - state.lastXPUpdate >= 1 then
local xpGain = 1
if stats.Time.Value >= 1000 then
local level = stats.Level.Value
xpGain = stats.Time.Value >= MAX_TIME and MAX_XP_PER_SECOND
or math.clamp(math.ceil(((math.clamp(stats.Time.Value,1000,MAX_TIME)-1000)/(MAX_TIME-1000))^0.25 * level * XPBoostPerLevel), 1, MAX_XP_PER_SECOND)
end
_G.awardXP(player, xpGain, "Explorer")
state.lastXPUpdate = now
end
if stats.Time.Value % 60 == 0 then
savePlayerStats(player)
end
end
else
state.canGainTime = false
state.lastTimeUpdate = now
end
end
end
game:BindToClose(function()
for _, plr in ipairs(Players:GetPlayers()) do
savePlayerStats(plr)
end
end)
or this script KillLog: ServerScriptService -> PlayerStatsManaging -> KillLog
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--RemoteEvent to trigger the client log
local logEvent = Instance.new("RemoteEvent")
logEvent.Name = "KillLogEvent"
logEvent.Parent = ReplicatedStorage
--Function to log kill to client
function logKillToClient(killer, victim, stolenTime, distance, toolName)
if not killer or not victim then return end
local killerStats = killer:FindFirstChild("leaderstats")
if not killerStats then return end
code
local currentTime = killerStats:FindFirstChild("Time") and killerStats.Time.Value or 0
logEvent:FireClient(killer, {
KillerName = killer.Name,
VictimName = victim.Name,
TimeNow = currentTime,
StolenTime = stolenTime,
Distance = distance,
ToolName = toolName or "Unknown"
})
end
Assistant
Great, thanks for the detailed info! The bug:
When a player with a lot of time (e.g., 84,039) is killed, the killer does not get that time transferred, even though it should.
Where the bug is likely happening
The StatsManagement script is the one handling the time transfer logic, specifically in the handleDeath function:
lua
if killer and killer:IsA("Player") and killer ~= player then
...
local kstats = killer:FindFirstChild("leaderstats")
if kstats then
local stolenTime = stats.Time.Value
kstats.Time.Value += stolenTime
stats.Time.Value = 0
...
end
end
This is the code that should transfer the time.
Possible reasons for the bug
stats.Time.Value is 0 at the time of transfer (maybe it was set to 0 earlier).
kstats.Time.Value is not updating due to a logic error or a Roblox replication issue.
The function is not being called when the player dies.
The kill is not being registered as a valid kill (e.g., due to safe zone logic or recentKills logic).
Debugging steps
1. Check if stats.Time.Value is correct before transfer
If both are not in a safe zone, the transfer should happen.
4. Check for recentKills logic
If the same kill is registered twice within 10 seconds, it might skip the transfer.
How to fix
1. Make sure time is not set to 0 before transfer
Check if any code sets stats.Time.Value = 0before the transfer.
In your code, the only place this happens is after the transfer, so this should be fine.
2. Make sure the function is always called
If the player dies in a safe zone, the time is set to 0 and not transferred.
If the killer is in a safe zone, the transfer should still happen.
Check this block:
lua
if kSafe or (not kSafe and not vSafe) then
-- transfer time
else
stats.Time.Value = 0
-- no transfer
end
If the victim is in a safe zone and the killer is not, no transfer happens and time is set to 0.
What to do next
Add debug prints to see what's happening:
lua
print("Killer:", killer, "Killer Safe:", kSafe, "Victim Safe:", vSafe)
print("Victim Time before transfer:", stats.Time.Value)
Test the following scenarios:
Both players outside safe zone
Killer in safe zone, victim outside
Victim in safe zone, killer outside
Potential fix
If you want time to always transfer when a player is killed, regardless of safe zone, change this logic:
lua
if kSafe or (not kSafe and not vSafe) then
-- transfer time
else
stats.Time.Value = 0
-- no transfer
end
To:
lua
if killer and killer:IsA("Player") and killer ~= player then
local kstats = killer:FindFirstChild("leaderstats")
if kstats then
local stolenTime = stats.Time.Value
kstats.Time.Value += stolenTime
stats.Time.Value = 0
-- rest of the code
end
end
Or, if you want to keep safe zone logic, make sure you understand when you want time to transfer.
Summary
The transfer logic is in handleDeath.
If the victim is in a safe zone and the killer is not, time is set to 0 and not transferred.
If you want time to always transfer, remove or adjust the safe zone check.
Add debug prints to see what's happening during kills.
Let me know if you want a specific code fix, or if you want to keep the safe zone logic but fix a bug within it!
If you can provide a test case (e.g., "I killed a player outside the safe zone and didn't get their time"), I can give you the exact code change.