I’ve written some code that allows a player to take a sip of the item “OrangeJuiceTool” in the StarterPack, and whenever a sip is taken, the Sips value in the script update and add one, however whenever a sip is taken, no values are added. Here is my code:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Sips = Instance.new("IntValue")
Sips.Name = "Sips"
Sips.Value = 0
Sips.Parent = Leaderstats
local tool = game.StarterPack:WaitForChild("OrangeJuiceTool")
local Data = DataStore:GetAsync(Player.UserId)
if Data then
Sips.Value = Data
end
local function IncrementSips()
Sips.Value = Sips.Value + 1
end
tool.Equipped:Connect(IncrementSips)
Player.CharacterAdded:Connect(function(Character)
local Tool = Character:FindFirstChildOfClass("Tool")
if Tool and Tool.Name == "OrangeJuiceTool" then
Tool.Activated:Connect(IncrementSips)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Sips.Value)
end)
I tried to update the code with different functions, didn’t work 🙁
New contributor
elujjin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.