#Datastore problem in a textbutton

23 messages · Page 1 of 1 (latest)

lime shale
#

SCRIPT WITHOUT DATASTORE (That works):
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local staf = player:WaitForChild("Stats")
local currency = stats:WaitForChild("Evolution")
local boostCurrency = stats:WaitForChild("Mutation")
local resetStats = {staf:WaitForChild("Money"), staf:WaitForChild("Multi"), staf:WaitForChild("Rebirth"), staf:WaitForChild("UltraRebirth"), staf:WaitForChild("Prestige"), staf:WaitForChild("UltraPrestige"), staf:WaitForChild("Hyper")}
local button = script.Parent

button.MouseButton1Click:Connect(function()
local cost = 100 + (boostCurrency.Value * 10)
if currency.Value >= cost then
currency.Value = currency.Value - cost
boostCurrency.Value = boostCurrency.Value + math.floor(currency.Value / cost)
for _, stat in pairs(resetStats) do
stat.Value = 0
end
else
print("Not enough Evolution to purchase boost.")
end
end)

#

SCRIPT WITH DATASTORE (that doesnt work):
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local staf = player:WaitForChild("Stats")
local currency = stats:WaitForChild("Evolution")
local boostCurrency = stats:WaitForChild("Mutation")
local resetStats = {staf:WaitForChild("Money"), staf:WaitForChild("Multi"), staf:WaitForChild("Rebirth"), staf:WaitForChild("UltraRebirth"), staf:WaitForChild("Prestige"), staf:WaitForChild("UltraPrestige"), staf:WaitForChild("Hyper")}
local button = script.Parent

local dataStore = game:GetService("DataStoreService"):GetDataStore("EvolutionDataStore")

-- Load player data
dataStore:GetAsync(player.UserId):andThen(function(data)
if data then
currency.Value = data.Evolution
boostCurrency.Value = data.Mutation
else
dataStore:SetAsync(player.UserId, {Evolution = 0, Mutation = 0})
end
end)

button.MouseButton1Click:Connect(function()
local cost = 100 + (boostCurrency.Value * 10)
if currency.Value >= cost then
currency.Value = currency.Value - cost
boostCurrency.Value = boostCurrency.Value + 1
for _, stat in pairs(resetStats) do
stat.Value = 0
end
dataStore:SetAsync(player.UserId, {Evolution = currency.Value, Mutation = boostCurrency.Value})
else
print("Not enough Evolution to purchase boost.")
end
end)

#

There aren't any errors in the Output

drowsy granite
#

DataStore doesnt work for local script i think

cobalt horizon
#

First Fix you leaderstats

#

So Leaderstats folder will appear when all values loaded

#

So, you don't need add WaitForChild except for leaderstats

#

And use Datastore inside leaderstats script

lime shale
#

Basically, without the datastore in the script, if i get Mutation with the textbutton and then i go "server" and open the folder "leaderstats" and i go in "mutation" i will see still 0 instead of the amount i bought from the textbutton, but in the leaderboard of the top right i will see the amount i bought from the button

frozen orioleBOT
#

studio** You are now Level 1! **studio

drowsy granite
#

anything locally will only show for the client

lime shale
#

Can you help me Please...xuCri

drowsy granite
#

fire a remote event via button script

#

in server script access the remote event and player then change mutation

lime shale
#

sorry, im stupid and i cant understand... im not a scripter

drowsy granite
#

i cant really help you then rn

#

srry

lime shale
#

oh...

plush hamlet
#

u need sevrer scrip

#

use remoteevents