Good afternoon, I have a DataStore2 script.I figured out how to connect it to the port via Click Detector.(at the end of the code, when you click on the object, you are given money, but I can’t connect it to the Ui, I tried using Mouseclick, it doesn’t work
–code
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local MoneyButton = game.StarterGui.ScreenGui.PlusMoney
local DataStore2 = require(ServerScriptService.DataStore2)
— Combine every key you use. This will eventually be the default, but for now read the "Gotchas" section to understand why we need this.
DataStore2.Combine("DATA", "points")
Players.PlayerAdded:Connect(function(player)
local pointsStore = DataStore2("points", player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local points = Instance.new("NumberValue")
points.Name = "Points"
points.Value = pointsStore:Get(0)
points.Parent = leaderstats
pointsStore:OnUpdate(function(newPoints)
— This function runs every time the value inside the data store changes.
points.Value = newPoints
end)
leaderstats.Parent = player
end)
Workspace.Part.ClickDetector.MouseClick:Connect(function(player)
local pointsStore = DataStore2("points", player)
pointsStore:Increment(1) — Give them 1 point
end)