TF_Killer
(Nezui)
February 18, 2021, 2:54am
#1
You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
i want to fix my script
What is the issue? Include screenshots / videos if possible!
my CurrentXP value and my MaxXp value keep setting to 0
heres my script
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
wait(.1)
local Settings = Instance.new("Folder")
Settings.Name = "Settings"
Settings.Parent = plr
local Lv = Instance.new("IntValue")
Lv.Name = "Level"
Lv.Parent = Settings
local Stamina = Instance.new("IntValue")
Stamina.Name = "Stamina"
Stamina.Parent = Settings
local MaxStamina = Instance.new("IntValue")
MaxStamina.Name ="MaxStamina"
MaxStamina.Parent = Settings
local Beli = Instance.new("IntValue")
Beli.Name = "Beli"
Beli.Parent = Settings
local CurrentXP = Instance.new("IntValue")
CurrentXP.Name = "CurrentXP"
CurrentXP.Value = 0
CurrentXP.Parent = Settings
local MaxXP = Instance.new("IntValue")
MaxXP.Name = "MaxXP"
MaxXP.Parent = Settings
MaxStamina.Value= 100
MaxXP.Value = 100
Stamina.Value = MaxStamina.Value
Beli.Value = 1000
Lv.Value = 1
local Data = nil
local succes , errr = pcall(function()
Data = MyDataStore:GetAsync(plr.UserId)
end)
if succes then
Lv.Value = Data.Level
MaxXP.Value = Data.MaxXP
CurrentXP.Value = Data.CurrentXP
Beli.Value = Data.Beli
if MaxStamina ~= 0 then
MaxStamina.Value = Data.MaxStamina
else
plr:Kick("Anti Cheat")
end
if Stamina.Value < MaxStamina.Value then
plr:Kick("Stamina error report to admin !")
end
-- Data here
else
warn(errr)
end
if Lv.Value > 450 then
plr:Kick("Hacking ")
else
warn("Accepted")
end
2 Likes
TF_Killer
(Nezui)
February 18, 2021, 2:56am
#2
its no printing error at the roblox studio output
55167233gf
(DJ_Galaxy)
February 18, 2021, 2:59am
#3
If you test it on studio. Then did not have error, please test on roblox
TF_Killer
(Nezui)
February 18, 2021, 3:01am
#4
ok, sure thx for your help XXD
Galactiq
(Matthew)
February 18, 2021, 3:02am
#5
Thereās a whole lot going on here. For one, the data reading should not be when the character is added. It should be taken outside of that function, and moved to only the PlayerAdded event function. Secondly, your script fails to check if a player does not have data. As far as I know, the data could be set to nil and still return successful. Lastly, I see no data saving . I see where you attempt to load the data, however it is cached interestingly and saved nowhere in the script.
TF_Killer
(Nezui)
February 18, 2021, 3:06am
#6
Galactiq:
Thereās a whole lot going on here. For one, the data reading should not be when the character is added. It should be taken outside of that function, and moved to only the PlayerAdded event function. Secondly, your script fails to check if a player does not have data. As far as I know, the data could be set to nil and still return successful. Lastly, I see no data saving . I see where you attempt to load the data, however it is cached interestingly and saved nowhere in the script.
so do u have any solustion to fix ?
Galactiq
(Matthew)
February 18, 2021, 3:10am
#7
I thought it was pretty self-explanatory.
Check and set default values if the player has no previous saves.
Save their data when they leave, or periodically if you wish.
Here are some helpful resources for you:
Saving Player Data
Data Stores
Data Store Update Async
Keep in mind the DevForum is not a place where people should write scripts for you. You need to tinker around with it and try to figure things out for yourself. My job is to point you in the right direction, which I have done. Best of luck to you.
You should not be loading data when the character is added ā¦
As Galactiq said we can not write the scripts for you.
However if you donāt understand what to do may i suggest removing the character added event and it should function correctly
55167233gf
(DJ_Galaxy)
February 18, 2021, 3:18am
#9
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")
Galactiq
(Matthew)
February 18, 2021, 3:20am
#10
You can write scripts for her, itās just not the intentions of the DevForum. You are in no way obligated to write someone a script.
Oh thanks for letting me know i will bear that in mind
1 Like
55167233gf
(DJ_Galaxy)
February 18, 2021, 3:24am
#12
Your script have many error:
Remove the character added function.
Add the DataStoreService value
Here is a fix that should work i havenāt got access to studio rn so i cant test but here you go:
DataStoreService=game:service(āDataStoreServiceā)
MyDataStore=DataStoreService:GetDataStore(āPlayerDataā)
game.Players.PlayerAdded:Connect(function(plr)
local Settings = Instance.new(āFolderā)
Settings.Name = āSettingsā
Settings.Parent = plr
local Lv = Instance.new(āIntValueā)
Lv.Name = āLevelā
Lv.Parent = Settings
local Stamina = Instance.new(āIntValueā)
Stamina.Name = āStaminaā
Stamina.Parent = Settings
local MaxStamina = Instance.new(āIntValueā)
MaxStamina.Name =āMaxStaminaā
MaxStamina.Parent = Settings
local Beli = Instance.new(āIntValueā)
Beli.Name = āBeliā
Beli.Parent = Settings
local CurrentXP = Instance.new(āIntValueā)
CurrentXP.Name = āCurrentXPā
CurrentXP.Value = 0
CurrentXP.Parent = Settings
local MaxXP = Instance.new(āIntValueā)
MaxXP.Name = āMaxXPā
MaxXP.Parent = Settings
MaxStamina.Value= 100
MaxXP.Value = 100
Stamina.Value = MaxStamina.Value
Beli.Value = 1000
Lv.Value = 1
local Data = nil
local succes , errr = pcall(function()
Data = MyDataStore:GetAsync(plr.UserId)
end)
if succes then
Lv.Value = Data.Level
MaxXP.Value = Data.MaxXP
CurrentXP.Value = Data.CurrentXP
Beli.Value = Data.Beli
if MaxStamina ~= 0 then
MaxStamina.Value = Data.MaxStamina
else
plr:Kick(āAnti Cheatā)
end
if Stamina.Value < MaxStamina.Value then
plr:Kick(āStamina error report to admin !ā)
end
else
warn(errr)
end
if Lv.Value > 450 then
plr:Kick("Hacking ")
else
warn("Accepted")
end
end)
Edit: Sorry for bad formatting ā¦
TF_Killer
(Nezui)
February 18, 2021, 3:25am
#14
sorry for not posting full script i aready did it
1 Like
TF_Killer
(Nezui)
February 18, 2021, 3:33am
#15
thx you guys! i just fixed it by myself thx for telling my script problems
1 Like
TF_Killer
(Nezui)
February 18, 2021, 3:34am
#16
thx! i will give you a green mark UwU