I want to add a steal time feature to my game but the script doesn’t work when the player first joins, pls help
local KilledEvent = ReplicatedStorage:WaitForChild("GFink's Resources"):WaitForChild("Events"):WaitForChild("Killed")
KilledEvent.Event:Connect(function(plr, target)
-- Check if the target has any time left
local targetUserId = target.UserId
local plrUserId = plr.UserId
if timeCounters[targetUserId] and timeCounters[targetUserId] > 0 then
-- Steal all of the target's time
timeCounters[plrUserId] = timeCounters[plrUserId] + timeCounters[targetUserId]
local success, errorOrResult = pcall(function()
dataStore:SetAsync(tostring(targetUserId), nil)
dataStore:SetAsync(tostring(plr.UserId), tostring(timeCounters[plr.UserId]))
end)
if not success then
warn("An error occurred: " .. tostring(errorOrResult))
end
end
end)
local KilledEvent = ReplicatedStorage:WaitForChild("GFink's Resources"):WaitForChild("Events"):WaitForChild("Killed")
KilledEvent.OnServerEvent:Connect(function(plr, target)
-- Check if the target has any time left
local targetUserId = target.UserId
local plrUserId = plr.UserId
if timeCounters[targetUserId] and timeCounters[targetUserId] > 0 then
-- Steal all of the target's time
timeCounters[plrUserId] = timeCounters[plrUserId] + timeCounters[targetUserId]
local success, errorOrResult = pcall(function()
dataStore:SetAsync(tostring(targetUserId), nil)
dataStore:SetAsync(tostring(plr.UserId), tostring(timeCounters[plr.UserId]))
end)
if not success then
warn("An error occurred: " .. tostring(errorOrResult))
end
end
end)