Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm trying to make a combat logging system. Can anyone tell me why this simple script will not work?

This script is located inside of the player and will only trigger if the player is in combat and leaves the game. Their data will be wiped. There are some problems though, sometimes the script doesn't even print anything. On the off chance it does, it doesn't even wipe data. Can anyone tell me why this will not work?

local ts = game:GetService("DataStoreService"):GetDataStore("ToolSave")
local gs = game:GetService("DataStoreService"):GetDataStore("GoldSave")
local ss = game:GetService("DataStoreService"):GetDataStore("SatrSave")

game.Players.PlayerRemoving:Connect(function(plr)
	print(plr.Name.." COMBAT LOGGED.")
		local key =  "ID- "..plr.UserId
		local key2 = plr.UserId
		local key3 = "PID-"..plr.UserId
		gs:RemoveAsync(key2)
		ss :RemoveAsync(key3)
		ts:RemoveAsync(key)
		print("DATA WIPED")
end)

1 comment

0

Try placing the script at the workspace, or ServerScriptService [Normal Script, not local]

1 answer

Hello, SnakeInTheBoots. You have made the script a regular/server script inside ServerScriptService. The client cannot tell whenever a player is getting added or removed and access DataStoreService. Plus, ServerScripts cannot run on players.

This discussion is preserved as it was. New answers, comments, and votes are closed.