I’m trying to make it that if a player has two things, Their 2 things get removed once they clicked on a button. However, When I Try to save that removal. It doesn’t save. It doesn’t show an error either.
The script is a localscript in StarterGui, I’ve tried moving in inside of the datasave script but it didn’t work.
Heres the Data save script
-- Data Save Script
local DataStore = game:GetService("DataStoreService")
local theStore = DataStore:GetDataStore("SomeDataStore_02") -- your datastore name
game.Players.PlayerAdded:Connect(function(player)
local success, data = pcall(function()
return theStore:GetAsync("Player_"..player.UserId)
end)
if success then
print("our data is alive")
local ValueHammer = Instance.new("IntValue", player)
ValueHammer.Name = "ValueHammer"
local ValueWood = Instance.new("IntValue", player)
ValueWood.Name = "ValueWood"
if data then
print("player in datastore found")
if data["ValueHammer"] then
ValueHammer.Value = data["ValueHammer"]
else
ValueHammer.Value = 0
end
if data["ValueWood"] then
ValueWood.Value = data["ValueWood"]
else
ValueWood.Value = 0
end
else
print("no player in datastore, should be new player")
ValueHammer.Value = 0
ValueWood.Value = 0
end
local clickDetector = game.Workspace.Spawn.Spawn["Meshes/stick"].ClickDetector
clickDetector.MouseClick:Connect(function()
ValueHammer.Value = ValueHammer.Value + 1
local clickDetector = game.Workspace.ClickaPArt.ClickDetector
local playerUserId = "Player_"..player.UserId
print(playerUserId)
end)
else
print("The data literally died")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if player:FindFirstChild("ValueHammer") then
local data = {
ValueHammer = player:FindFirstChild("ValueHammer").Value,
ValueWood = player:FindFirstChild("ValueWood").Value
}
local succ, err = pcall(function()
return theStore:SetAsync("Player_"..player.UserId, data)
end)
if succ then
warn(data, "our data lives to see another day")
else
warn("Unable to save the data")
warn(err)
end
end
end)
script.Parent.Sticks.Text = "Sticks: "..Velue.Value
Velue.Changed:Connect(function()
script.Parent.Sticks.Text = "Sticks: "..Velue.Value
end)
script.Parent.Wood.Text = "Wood: "..Velue.Value
WoodVelue.Changed:Connect(function()
script.Parent.Wood.Text = "Wood: "..WoodVelue.Value
end)
WoodButton.MouseButton1Up:Connect(function()
if game.Players.LocalPlayer:WaitForChild("ValueWood").Value >= 1 and game.Players.LocalPlayer:WaitForChild("ValueHammer").Value >= 1 then
local WoodPickClone = game.StarterGui.Crafting.Tools["Wood Pickaxe"]:Clone()
WoodPickClone.Parent = game.Players.LocalPlayer.Backpack
game.Players.LocalPlayer:WaitForChild("ValueHammer").Value = game.Players.LocalPlayer:WaitForChild("ValueHammer").Value - 1
game.Players.LocalPlayer:WaitForChild("ValueWood").Value = game.Players.LocalPlayer:WaitForChild("ValueWood").Value - 1
end
end)
This is the script thats Removes value from the item
local WoodButton = script.Parent.Parent.CraftingMenu.WoodenPickaxe
WoodButton.MouseButton1Up:Connect(function()
if game.Players.LocalPlayer:WaitForChild("ValueWood").Value >= 1 and game.Players.LocalPlayer:WaitForChild("ValueHammer").Value >= 1 then
local WoodPickClone = game.StarterGui.Crafting.Tools["Wood Pickaxe"]:Clone()
WoodPickClone.Parent = game.Players.LocalPlayer.Backpack
game.Players.LocalPlayer:WaitForChild("ValueHammer").Value = game.Players.LocalPlayer:WaitForChild("ValueHammer").Value - 1
game.Players.LocalPlayer:WaitForChild("ValueWood").Value = game.Players.LocalPlayer:WaitForChild("ValueWood").Value - 1
end
end)