Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

DataStore leaderstats not updating?

Asked by
AAzterr 27
5 years ago
Edited 5 years ago

So, I am trying to make a Part that awards the player with PlayerPoints and updates some DataStore leaderstats also when it's touched. Everything is working fine, but when I insert the part of the code that's supposed to change the leaderstats, it breaks. I took this part from this article on the wiki: api-reference/function/Players/GetPlayerFromCharacter The output gives out no errors too. Leaderstats are stored in a folder inside the player with an IntValue in it.

This is the code: (I added comments indicating where that part starts, and where it ends)

local PointsService = game:GetService("PointsService")
local debounce = false

local Players = game:GetService("Players") -- This line is part of the leaderstat awarder



script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

if not debounce then

debounce = true

if script.Parent.Name == "DuplicatedLol" then

PointsService:AwardPoints(game.Players[hit.Parent.Name].UserId,75)

local player = Players:GetPlayerFromCharacter(script.Parent) -- This line starts the leaderstat awarder part

if not player then return end

if player then

player.leaderstats.Points.Value = player.leaderstats.Points.Value + 75 -- This line ends the leaderstat award part

wait(0.5)

script.Parent:Destroy()

end

end

end

end

end)

Here's the DataStore script:

local DataStore = game:GetService("DataStoreService")

local ds = DataStore:GetDataStore("PointsSaved")



game.Players.PlayerAdded:Connect(function(player)

local ppstats = Instance.new("Folder", player)

ppstats.Name = "leaderstats"

local Points = Instance.new("IntValue",ppstats)

Points.Name = "Points"

Points.Value = ds:GetAsync(player.UserId) or 0

ds:SetAsync(player.UserId, Points.Value)

Points.Changed:Connect(function()

ds:SetAsync(player.UserId, Points.Value)

end)

end)



game.Players.PlayerRemoving:Connect(function(player)

ds:SetAsync(player.UserId, player.leaderstats.Points.Value)

end)

Hopefully I'm not screwing up something easy.

1
You're not even using DataStores, so why does the question title say it even though you're not using them? DeceptiveCaster 3761 — 5y
0
Also, is this a local script or normal script? DeceptiveCaster 3761 — 5y
0
I am. One sec, I'll edit the post to have the DataStore script. Also, both are ServerScripts. AAzterr 27 — 5y
0
Done. AAzterr 27 — 5y
View all comments (3 more)
0
Oh and, they both are separate scripts. The first one is located inside the part that awards the player, and the second one is stored inside ServerScriptService. AAzterr 27 — 5y
1
Change GetPlayerFromCharacter(script.Parent) to GetPlayerFromCharacter(hit.Parent). DeceptiveCaster 3761 — 5y
0
ah thanks a bunch, that worked AAzterr 27 — 5y

Answer this question