Basically, I want to know how to create a combat log system where players who are attacked or attack another player enter in combat and during this, if they were to leave, they would get penalized such as losing cash within their leaderstats. I tried looking for tutorials on this but I was unable to find any that help me on my situation. I’m somewhat new to scripting so if you can try to make this simple, would be greatly appreciated. I also have knowledge on using creator tags.
When they leave check if they are combat logged
a simple way to do this is by storing a BoolValue inside the player and when they shoot their gun or get damaged you set it to true. Only if they haven’t been hit or haven’t shot for 20 seconds or so you set it back to false.
Then when they leave you check if the boolvalue is true and if it is you know they left while still being in combat.
a server script that assigns a combat state to all players that detects the player using a tool or generally just attacking, a timer that turns it off if they haven’t attacked in a while, and a game.BindToClose() event, which detects clients closing the game
I’m not too familiar with bool values as I don’t really use them. Do you have an example of how I could use one in a script?
Hmm, should I make a datastore while trying to make this to save the data for this script then?
its just true or false value
local boolValue = Instance.new("BoolValue", player)
boolValue.Value = true
if boolValue.Value then -- it fires
end
yeah, you’d wanna have a key in the plr data store that’s a boolean (something like ["UnfairLeave"] = true
)
Yes, I watched through this and this is fantastic, exactly what I’m looking. However, I was only able to make it work with parts but not through a weapon with creator tags dealing with the leaderboard. Not to mention, the data storage seems kind of buggy and it saves randomly 50/50.
Well… I dont know how his/her/that system works.
How i would do it:
- make a
bool
, orattribute
on the character, or the player that keeps track if player is in combat. - When player swings tool or does any action, we set the
bool/attribute
totrue
- When player leaves we check if player/char is in combat and then we save that to a
datastore
- Plr joins we simply check if plr is indeed combat logged and we will “punish” the plr by for example halving his cash. For that to work we need his
cash
and then divide it by 2. - We update the cash on the server and yeah, done
--script 1
local d = game:GetService("DataStoreService")
local plrs = game:GetService("Players")
local dataSt = d:GetDataStore("SaveMoney")
local pr = "_Monee"
local function save(plr:Player)
local data = plr.leaderstats.Money.Value
local s, er = pcall(function()
dataSt:SetAsync(plr.UserId..pr, data)
end)
if not s then
warn(er)
end
end
local function load(plr:Player)
local data
local s, er = pcall(function()
data = dataSt:GetAsync(plr.UserId..pr)
end)
if not s then
warn(er)
else
if data ~= nil then
plr.leaderstats.Money.Value = data
end
end
end
local function make(plr:Player)
local f = Instance.new("Folder")
f.Name = "leaderstats"
f.Parent = plr
local m = Instance.new("NumberValue")
m.Name = "Money"
m.Parent = f
m.Value = 0
load(plr)
end
plrs.PlayerAdded:Connect(make)
plrs.PlayerRemoving:Connect(save)
game:BindToClose(function()
for _, plr in plrs:GetPlayers() do
save(plr)
end
end)
--script2
local d = game:GetService("DataStoreService")
local plrs = game:GetService("Players")
local dataSt = d:GetDataStore("SaveClog")
local pr = "_Log"
local function save(plr:Player)
local data = plr:GetAttribute("Combat")
local s, er = pcall(function()
dataSt:SetAsync(plr.UserId..pr, data)
end)
if not s then
warn(er)
end
end
local function load(plr:Player)
local data
local s, er = pcall(function()
data = dataSt:GetAsync(plr.UserId..pr)
end)
if not s then
warn(er)
else
if data ~= nil then
plr:SetAttribute("Combat", data)
end
end
end
local function make(plr:Player)
plr:WaitForChild("leaderstats")
plr:SetAttribute("Combat", false)
load(plr)
if plr:GetAttribute("Combat") == true then
plr.leaderstats.Money.Value /= 2
plr:SetAttribute("Combat", false)
end
end
plrs.PlayerAdded:Connect(make)
plrs.PlayerRemoving:Connect(save)
game:BindToClose(function()
for _, plr in plrs:GetPlayers() do
save(plr)
end
end)
Wrote this quick and easy script for you, i hope this helps you.
Thank you for your help, I wasn’t able to get it to exactly work but I did manage to make my own combat log script that only currently works when someone gets damaged. I tried to use yours but I was unable to get it to work with the weapon script I have which is the FE gun kit. I kind of used yours like a blueprint/reference to make my own. Mine currently works as the player loads in now, they get kills, and if they get damaged by something and if they leave while in combat, they lose basically their money. I’m trying to figure out how to make it so it only affects the player and the player who damaged them.
Can you explain what you mean with this? DM me, i want to help you.
I sent you a DM message explaining what i’m trying to achieve.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.