i looked all over the developer hub and i cant find anything, and api services are on, this is also one of the same scripts i used in my other game so this makes no sense to me
local DataStoreService = game:GetService("DataStoreService")
local inventorySpace = DataStoreService:GetDataStore("inventorySpaceStore")
game.Players.PlayerAdded:Connect(function(player)
local SavedData = inventorySpace:GetAsync(player.UserId)
local Space = Instance.new("NumberValue", player)
Space.Name = "inventorySpace"
Space.Value = SavedData or 0
Space.Changed:Connect(function()
print("inventory space changed")
inventorySpace:SetAsync(player.UserId, Space.Value)
print("saved")
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local succ, err = pcall(function()
inventorySpace:SetAsync(player.UserId, player.inventorySpace.Value)
end)
if not succ then
if err then
warn("[DB] Failed to set "..(player.Name).."'s info: ", err)
else
warn("[DB] Failed to set "..(player.Name).."'s info. No error returned.")
end
end
end)
that is my script, no idea why it wont save either when the player leaves the game or when the value changes. I am getting no errors or anything, please help
I’m not sure if there is another script reading the numberValue on the client however from my observations you pared the values to the player rather than the leaderstats. Not sure if this was intentional
i have other local scripts reading the number value. but what do you mean i pared the values to the player rather then the leaderstats? im not entirely sure what you mean
local canHit = true
local db = 1
script.Parent.CritterHitterPart.Touched:Connect(function(thing)
if thing.Parent.Name == "Cricket" and thing.Name == "Handle" then
if canHit == true then
canHit = false
print("hit critter")
game.Players.LocalPlayer.inventorySpace.Value = game.Players.LocalPlayer.inventorySpace.Value + 1
wait(db)
canHit = true
end
end
end)
thats the script that changes the value and it seems to work fine no errors out of that either and its coming from a local script inside of a tool
i literally just realized thats my issue its coming from a local script so i would need to fire a remote event for it to change the value on the server side. right?
ah i see, it’s not working because that script is on the client (i can tell by the use of
localplayer)
so the server won’t get the changes made from the client because of something called filtering enabled which means client cannot replicate to the server or other clients.
So you would need to put this script on the server and get the player value by validating that whatever touched the part was a player (loads of methods to do this) and then increment the value there