dude you guys still here the issue is so easy but your coding is just weird
Hey, it doesnât have any errors in output, but it doesnât really save quite properly, like, the cash only updates if I have changed the script significantly. I donât know how to explain it quite well.
local conf = game.ReplicatedStorage:WaitForChild("Configuration")
local currencyName = conf:WaitForChild("CurrencyName")
local LoadData = require(game.ServerScriptService.ShopServer.ModuleScripts.LoadData)
local ShopServer = game.ServerScriptService:WaitForChild("ShopServer")
local SaveData = require(ShopServer.ModuleScripts:WaitForChild("SaveData"))
-- Function to give cash to the creator of the killed player and save data after each kill
local function OnPlayerDeath(character)
local creatorTag = character.Humanoid:FindFirstChild("creator")
if creatorTag and creatorTag.Value then
local stats = creatorTag.Value:FindFirstChild("leaderstats")
if stats then
local cashStat = stats:FindFirstChild(currencyName.Value)
if cashStat then
cashStat.Value = cashStat.Value + 20 -- Reward the creator with 20 cash
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local success = SaveData(player) -- Save player data after each kill
if success then
print("Data saved successfully for player:", player.Name)
else
warn("Failed to save data for player:", player.Name)
end
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
-- Listen for character added events
player:WaitForChild("leaderstats")
local loadedData = LoadData(player)
if loadedData then
player.leaderstats:WaitForChild(currencyName.Value).Value = loadedData.Cash or 0
end
player.CharacterAdded:Connect(function(character)
-- Listen for player deaths
character:WaitForChild("Humanoid").Died:Connect(function()
OnPlayerDeath(character)
end)
end)
end)
Maybe I did something wrong here? I donât really quite knowâŚ