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!
Like in the title, I want a intvalue to change in Game, too. Not just in the Script. (ServerScriptService Script)
What is the issue? Include screenshots / videos if possible!
IntValue changes in Script but not in Game
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to change the value in another script, but the same result.
local ds = game:GetService("DataStoreService")
local dataStore = ds:GetDataStore("LeaderstatsData")
game.Players.PlayerAdded:Connect(function(plr)
local data = nil
local sucess, errorMessage = pcall(function()
data = dataStore:GetAsync(plr.UserId)
end)
if not sucess then
print(errorMessage)
end
print(data)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local souls = Instance.new("IntValue", leaderstats)
souls.Name = "Souls"
souls.Value = 0
if data ~= nil then
if data[1] ~= nil then
souls.Value = data[1]
end
end
local gems = Instance.new("IntValue", leaderstats)
gems.Name = "Gems"
if data ~= nil then
if data[2] ~= nil then
gems.Value = value
print(gems.Value) --prints out the saved data. Leaderstats doesn't change.
end
end
local privateValues = Instance.new("Folder", plr)
privateValues.Name = "privateValues"
local gemMultiplication = Instance.new("IntValue", privateValues)
gemMultiplication.Name = "gemMultiplication"
if data ~= nil then
if data[3] ~= nil then
gemMultiplication.Value = data[4]
end
end
local soulMultiplication = Instance.new("IntValue", privateValues)
soulMultiplication.Name = "soulMultiplication"
if data ~= nil then
if data[4] ~= nil then
gems.Value = data[4]
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = {
plr.leaderstats.Souls.Value,
plr.leaderstats.Gems.Value,
plr.privateValues.gemMultiplication.Value,
plr.privateValues.soulMultiplication.Value
}
local sucess, errorMessage = pcall(function()
dataStore:SetAsync(plr.UserId, data)
end)
if not sucess then
print(errorMessage)
end
end)
Found a way for something against this. If you have the same error then here is my solution:
buggyValue(yourIntOrStringValue, normalValue)
function buggyValue(value, normalValue)
value.Value = normalValue
local buggyRepeat = true
spawn(function()
wait(1)
buggyRepeat = false
end)
value.Changed:Connect(function()
if buggyRepeat then
value.Value = normalValue
end
end)
end
local ds = game:GetService("DataStoreService")
local dataStore = ds:GetDataStore("LeaderstatsData")
local plrs = game:GetService("Players")
plrs.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local souls = Instance.new("IntValue")
souls.Parent = leaderstats
souls.Name = "Souls"
souls.Value = 0
local gems = Instance.new("IntValue")
gems.Parent = leaderstats
gems.Name = "Gems"
gems.Value = 0
local privateValues = Instance.new("Folder")
privateValues.Parent = plr
privateValues.Name = "privateValues"
local gemMultiplication = Instance.new("IntValue")
gemMultiplication.Parent = privateValues
gemMultiplication.Name = "gemMultiplication"
gemMultiplication.Value = 0
local soulMultiplication = Instance.new("IntValue")
soulMultiplication.Parent = privateValues
soulMultiplication.Name = "soulMultiplication"
soulMultiplication.Value = 0
local data = nil
local succ, err = pcall(function()
data = dataStore:GetAsync(plr.UserId)
end)
if not succ then
warn(err)
end
if type(data) == "table" then
souls.Value = data[1] or 0
gems.Value = data[2] or 0
gemMultiplication.Value = data[3] or 0
soulMultiplication.Value = data[4] or 0
end
end)
plrs.PlayerRemoving:Connect(function(plr)
local data = {
plr.leaderstats.Souls.Value,
plr.leaderstats.Gems.Value,
plr.privateValues.gemMultiplication.Value,
plr.privateValues.soulMultiplication.Value
}
local succ, err = pcall(function()
dataStore:SetAsync(plr.UserId, data)
end)
if not succ then
warn(err)
end
end)
Instance all of the necessary instances first, then load the stored values at once. Also, avoid using the parent parameter of the instance class constructor function “Instance.new()”.