#[PLS HELP] i want to make a script to add a warning to the player leaderstat but how do i do this?
369 messages · Page 1 of 1 (latest)
how do i make it so it adds up
i want to change this part so i have to enter the player id in stead of making a whole admin system
can someone give me a fixed script?
could you do ```lua
print(OnPlayerChatted(rustyrean2011, "!warn rustyrean2011"))
put the line at the bottom of the script
alright hold on
print(OnPlayerChatted(game.Players.rustyrean2011, "!warn rustyrean2011"))```
anyhow
wait what
rustyrean2011
looks about right
well
i think i figured out why it did that
print(OnPlayerChatted(game.Players.rustyrean2011, "!warn rustyrean2011"))```
these are all the scripts btw
this should in theory return something in output
this should make it a bit more readable
wait(1)
print("OVERHERE!")
print(OnPlayerChatted(game.Players.rustyrean2011, "!warn rustyrean2011"))```
if it doesnt print then it means the script isnt working
no
i deleted all scripts the only script about warnings is this one now
so i need to create a simple script to give people warnings
** You are now Level 3! **
the last script even though it was ai technically is functional
can you paste the script here?
alright
-- Server Script (ServerScriptService)
-- Function to handle when a player joins the game
local function PlayerAdded(player)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
Warnings.Value = 0 -- Set initial Warning value to 0
Warnings.Parent = leaderstats
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
-- Clean up player data if needed
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)
it seems the issue the entire time was the fact the isAdmin variable was ticked false
i tried to make it true
when i said !warn rustyrean2011 it didnt gave an error in the output but it didnt give me a warning either
i undeleted the script
it doesnt give an error
but it doesnt give me a warning either
under lua local targetPlayer = blah blah blah
put down
print("ISSUEHERE!")
print(targetPlayer)```
where is local targetplayer thingt
in this script
here\
yes
so now
does the error log have anything?
ah yes
before setting warning.value, you should create something like
local amount = 1```
which will add 1 warning
** You are now Level 5! **
yes
tysm
but a slight slight problem
if i have this doesnt it mean everyone can use the command
yep so
so i want to enter like a player id
that i have to enter a player id and then that players gets the command
replace local isadmin with
local isAdmin
if player.Name = "USERNAMEHERE" then isAdmin = true else return 0 end```
right
alright lets see
btw
one more thing
if you ever have a list of players you could do something like
local isAdmin
local list = {
"USERNAMEHERE";
}
if table.find(list,player.Name) then isAdmin = true else return 0 end```
sort of
its creating a table
im not actually sure if it will all work through
but it should
in theory
but htis one works too right
im pretty sure it does
you gotta create a table for these kind of things
like this?
i mean
you gotta use datastore service i think
i havent used datastore service in a while
but it shouldnt be too hard
wait how do you make the text like this
** You are now Level 4! **
how to do the komma
ah
i cant press enter
grr
so i asked chatgpt for a leaderstat saving script
and im not sure if it works
i have no idea if this works
local function PlayerAdded(player)
local ds = dss:GetDataStore("warns"):GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
Warnings.Value = ds
else
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Parent = leaderstats
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:GetDataStore("warns"):SetAsync(player.UserId, player:FindFirstChild("leaderstats").Warnings.Value)
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
anyways
dont forget to go to game settings
then security
and enable datastores
it doesnt work ._.
or else it wont work
yes
so the chatgpt doesnt work
you gotta write an entire essay
describing your project
in order for it to understand what you want
any errors?
i dont think so
local dss = game:GetService("DataStoreService")
local function PlayerAdded(player)
local ds = dss:GetDataStore("warns"):GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
Warnings.Value = ds
else
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Parent = leaderstats
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:GetDataStore("warns"):SetAsync(player.UserId, player:FindFirstChild("leaderstats").Warnings.Value)
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
i forgor to add dss to the script ig
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
Warnings.Value = ds
else
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Parent = leaderstats
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player:FindFirstChild("leaderstats").Warnings.Value)
print(player.Name.." has left with warnings : "..player:FindFirstChild("leaderstats").Warnings.Value)
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
i have no clue if this will work
if it wont work
the error message will say
hm
i need to see what the print message was before
it should print a message containing the amount of warnings the player has after leaving the game
wdym
this line
print(player.Name.." has left with warnings : "..player:FindFirstChild("leaderstats").Warnings.Value)
prints a message when you leave the game
like this
damn
wait
you havent left the game yet
when you leave the game
it will print the message
uh
just this script
its basically a replacement of this script
just uh
remove the new script
for the script you had before
replace with the new code
yes
mk
now see if the warnings save
after leaving the game
show the output error log
if it contains your username and the amount of warnings you got
doesnt save
** You are now Level 5! **
replace
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player:FindFirstChild("leaderstats").Warnings.Value)
print(player.Name.." has left with warnings : "..player:FindFirstChild("leaderstats").Warnings.Value)
end```
with
```lua
local function PlayerRemoving(player)
print("test")
print(player.Name)
dss:SetAsync(player.UserId, player:FindFirstChild("leaderstats").Warnings.Value)
print(player.Name.." has left with warnings : "..player:FindFirstChild("leaderstats").Warnings.Value)
end```
and then run the game, stop it and check the output
like this
yep
mmm yea
local function PlayerRemoving(player)
print("test")
print(player.Name)
dss:SetAsync(player.UserId, player:FindFirstChild("leaderstats").Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
end```
if it doesnt work
then i know the problem
and it is not very fun to fix
** You are now Level 6! **
eh
hmm
wait
like this
that is the exact same line
i think i forgot to paste the right one
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player.leaderstats.Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
end```
yes
mhm
nothing appeared sadly
mk
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
player.leaderstats.Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
Warnings.Parent = leaderstats
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player.leaderstats.Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
checklist.[player.UserId]
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
replace the entire script
yes
hol up
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
player.leaderstats.Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
Warnings.Parent = leaderstats
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player.leaderstats.Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
checklist.[player.UserId] = nil
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
this should get rid of the squiggly lines
erm the whole leaderstat doesnt work
this one
i replaced it with this
that script
you poste
but the whole leaderstat doesnt show
this is the patch
this is the old one that i told you to replace with
i know but if i replace it with the old script the leaderstat wont even show
i replaced that
with that
new
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Parent = leaderstats
player.leaderstats.Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player.leaderstats.Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
checklist.[player.UserId]
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
gotta pray no sneaky bugs make this script fail
still
and again
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create warning stat
local Warnings = Instance.new("IntValue")
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Parent = leaderstats
Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player.leaderstats.Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
checklist.[player.UserId]
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
:(
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
-- Create warning stat
local Warnings = Instance.new("IntValue",leaderstats)
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, player.leaderstats.Warnings.Value)
print(player.Name.." has left with warnings : "..player.leaderstats.Warnings.Value)
checklist[player.UserId] = nil
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
yay
test datastore
so
okay
start the game
stop the game
check console
see if there is a message
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
-- Create warning stat
local Warnings = Instance.new("IntValue",leaderstats)
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
dss:SetAsync(player.UserId, checklist[player.UserId])
print(player.Name.." has left with warnings : "..checklist[player.UserId])
checklist[player.UserId] = nil
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)``` diceroll
the script has a part of its function changed
telling you which function is alot slower than replacing the entire script
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
-- Create warning stat
local Warnings = Instance.new("IntValue",leaderstats)
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
print("send help")
print(player.UserId)
print(checklist[player.UserId])
dss:SetAsync(player.UserId, checklist[player.UserId])
print(player.Name.." has left with warnings : "..checklist[player.UserId])
checklist[player.UserId] = nil
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
it should send print messages
100%
yes
it stopped when trying to save the data
i prolly did something wrong
i ran out of ideas
i guess just
double check game settings
like
alr
i did it exactly like the documentation did it
slight problem i once tried to enable it
but i have these teleporters in my game
and they dont teleport if i use them
like this
local checklist = {}
local dss = game:GetService("DataStoreService"):GetDataStore("warns")
local function PlayerAdded(player)
local ds = dss:GetAsync(player.UserId)
-- Create leaderstats folder for the player
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
-- Create warning stat
local Warnings = Instance.new("IntValue",leaderstats)
Warnings.Name = "Warnings"
if ds then
checklist[player.UserId] = ds
Warnings.Value = ds
else
checklist[player.UserId] = 0
Warnings.Value = 0 -- Set initial Warning value to 0
end
Warnings.Value.Changed:Connect(function()
checklist[player.UserId] = player.leaderstats.Warnings.Value
end)
end
-- Function to handle when a player leaves the game
local function PlayerRemoving(player)
print("send help")
print(player.UserId)
print(checklist[player.UserId])
local setSuccess, errorMessage = pcall(function()
dss:SetAsync(player.UserId, checklist[player.UserId])
end)
if not setSuccess then
warn(errorMessage)
end
print(player.Name.." has left with warnings : "..checklist[player.UserId])
checklist[player.UserId] = nil
end
-- Connect player join and leave events
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)```
all this will do is
display a fun error message
if it doesnt
then idk
fr