local MoneyStore = DataStoreService:GetDataStore("Moneyds")
local RebirthStore = DataStoreService:GetDataStore("Rebirthsds")
local button = game.StarterGui.ScreenGui.TextButton
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Money = Instance.new("IntValue",leaderstats)
Money.Name = "Money"
Money.Value = MoneyStore:GetAsync(player.UserId) or 0
local Rebirths = Instance.new("IntValue",leaderstats)
Rebirths.Name = "Rebirths"
Rebirths.Value = RebirthStore:GetAsync(player.UserId) or 0
button.MouseButton1Click:Connect(function(player)
Money.Value = Money.Value + 1
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
MoneyStore:UpdateAsync(player.UserId,player.leaderstats.Money.Value)
RebirthStore:UpdateASync(player.UserId,player.leaderstats.Money.Value)
end)
end)
there are no errors in the output, but when i click the button nothing happens
First of all, is this a server script or a local script?
Regular script inside of serverscriptservice
Then, you cannot use server scripts for UI stuff. You should use local scripts instead.
You are supposed to be calling the button from the playerâs PlayerGui not from the StarterGui, the StarterGui is only there for holding Gui objects not for calling it, you should be detecting the MouseButton1Click event in a local script not on the server.
Then how can I call the leaderstats?
You can place a remove event in replicated storage, then fire that event from the client whenever the button is clicked, and update the leaderstats on server event.
Could you help me make the script? Basically every time the button is pressed the players money goes up by one.
You should rather use a Remote event so that when you click a button then you can fire the remote event to the server which then can add up your money value. So first of all add a remote event in the ReplicatedStorage and do this:
Script
local MoneyStore = DataStoreService:GetDataStore("Moneyds")
local RebirthStore = DataStoreService:GetDataStore("Rebirthsds")
local button = game.StarterGui.ScreenGui.TextButton
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Money = Instance.new("IntValue",leaderstats)
Money.Name = "Money"
Money.Value = MoneyStore:GetAsync(player.UserId) or 0
local Rebirths = Instance.new("IntValue",leaderstats)
Rebirths.Name = "Rebirths"
Rebirths.Value = RebirthStore:GetAsync(player.UserId)
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
Money.Value = Money.Value + 1
end)
Localscript
Button.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer() -- make sure you have created a remote event in the replicated storage
end)
and also make sure to call the Button from the playerâs gui, like this:
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Button = PlayerGui:WaitForChild("Button")
--Local script
local remoteEvent = --navigate to the event, preferably in ReplicatedStorage
local button = -- navigate to the button
button.MouseButton1Click:Connect(function()
remoteEvent:FireServer()
end)
--Server script
local remoteEvent = --navigate to the event, preferably in ReplicatedStorage
remoteEvent.OnServerEvent:Connect(function(player)
player.leaderstats.Money.Value += 1
--[[ This is the same as saying:
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
]]
end)
10:04:14.309 - Infinite yield possible on âPlayers.U_npluggedDev:WaitForChild(âPlayerGUIâ)â
10:04:03.628 - Infinite yield possible on âRobloxReplicatedStorage:WaitForChild(âGetServerVersionâ)â
I got 2 errors in orange
Its PlayerGui not PlayerGUI, mhm
10:04:03.628 - Infinite yield possible on âRobloxReplicatedStorage:WaitForChild(âGetServerVersionâ)â
Did you add a remote event in the replicated storage?
yes. RemoteEvent. What does GetServerVersion mean tho
This is Roblox side error. It has nothing to do with your script.
Iâm not actually sure, I have had that error before, might be something to do with something else.