lol you can who said that you can’t do that
Give me one example of a working regular script inside of StarterCharacterScripts.
it will just put script that you left in startercharacterscripts in all characters that join
Please don’t argue anymore and tell me what’s wrong with the script cause I cant figure it out
did it worked or no the one i send
Could you play test the game and show me your explorer under your player in Players
please?
It didn’t work… I don’t know why this is not workingggg
it will work only when you will kill someone
Alright. Bingo. I was being stupid. Delete your leaderstats script and your datastore script. Delete the script in StarterCharacterScripts too.
Make a new regular script in ServerScriptService.
Then paste this code inside:
local Players = game:GetService("Players")
local TestService = game:GetService("TestService")
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStoreValues") --Name the DataStore whatever you want
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Strength = Instance.new("IntValue")
Strength.Name = "Strength"
Strength.Parent = leaderstats
Strength.Value = 0
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
local Stars = Instance.new("IntValue")
Stars.Name = "Stars"
Stars.Parent = leaderstats
Strength.Value = 0
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = leaderstats
Kills.Value = 0
local value1Data = Strength
local value2Data = Coins
local value3Data = Stars
local value4Data = Kills
player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value~= nil then
leaderstats.Kills.Value += 1
end
end)
end)
local s, e = pcall(function()
value1Data = DataStore:GetAsync(player.UserId.."-Value1") or 0 --check if they have data, if not it'll be "0"
value2Data = DataStore:GetAsync(player.UserId.."-Value2") or 0
value3Data = DataStore:GetAsync(player.UserId.."-Value3") or 0
value4Data = DataStore:GetAsync(player.UserId.."-Value4") or 0
end)
if s then
Strength.Value = value1Data --setting data if its success
Coins.Value = value2Data
Stars.Value = value3Data
Kills.Value = value4Data
else
TestService:Error(e) --if not success then we error it to the console
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local s, e = pcall(function()
DataStore:SetAsync(player.UserId.."-Value1", player.leaderstats.Strength.Value) --setting data
DataStore:SetAsync(player.UserId.."-Value2", player.leaderstats.Coins.Value)
DataStore:SetAsync(player.UserId.."-Value3", player.leaderstats.Stars.Value)
DataStore:SetAsync(player.UserId.."-Value4", player.leaderstats.Kills.Value)
end)
if not s then TestService:Error(e)
end
end)
game:BindToClose(function(player)
if not RunService:IsStudio() then
local s, e = pcall(function()
DataStore:SetAsync(player.UserId.."-Value1", player.leaderstats.Strength.Value) --setting data
DataStore:SetAsync(player.UserId.."-Value2", player.leaderstats.Coins.Value)
DataStore:SetAsync(player.UserId.."-Value3", player.leaderstats.Stars.Value)
DataStore:SetAsync(player.UserId.."-Value4", player.leaderstats.Kills.Value)
end)
if not s then TestService:Error(e)
end
end)
end
Now try changing it manually in the server and check if it works.
It has the same problem as the last one. The leaderstats doesn’t apear…
Are you positive that both the DataStore script and your previous leaderstats scripts is deleted? And that the script @madonchik123 told you to add in StarterCharacterScripts is deleted as well?
It works perfectly fine for me.
Also, I see that its working in your screenshot.
StarterCharacterScripts goes into character not player
I’m aware of that.
In the screenshoot that’s the script that I created. And yes, al the scripts are gone. I will try it in a baseplate to see if it’s works for me too
I changed the value of the kills and it worked. But it’s manually.
Wait wait wait! I found that in you script at the final the ends were wrong so I fixed them and now the leaderstats is apearing but when I kill an NPC from tooblox the kills value doesn’t go up. But when I colelct a coin the coins value are going up. Is that because I use an NPC and not a real player??
Correct. It needs to be a real player in order for it to work.
But does the script work now?
Wait I will test it with an real player and I will text you if will work!