I made a stats update Gui to display and change values local to a player. The server doesn’t seem to save them between sessions and I can’t call the changes when referencing them via a coin collection script. Joined game with 1 rebirth point and placed it into “Increased Coins”. Am I supposed to do something with the DataStoreService when altering values inside a player from a local script?
---- Increase and decrease the bonus coins value for the player ----
local player = game.Players
local textLabel = script.Parent
local bonusCoins = player.LocalPlayer.playerstats.BonusCoins
local upButton = script.Parent.Parent.UpButton
local downButton = script.Parent.Parent.DownButton
local rebirthToken = player.LocalPlayer.playerstats.RebirthToken
upButton.MouseButton1Click:Connect(function()
if rebirthToken.Value ~= 0 or nil then
rebirthToken.Value = rebirthToken.Value - 1
bonusCoins.Value = bonusCoins.Value + 1
task.wait(0.01)
end
end)
downButton.MouseButton1Click:Connect(function()
if bonusCoins.Value ~= 0 or nil then
bonusCoins.Value = bonusCoins.Value - 1
rebirthToken.Value = rebirthToken.Value + 1
task.wait(0.01)
end
end)
local function updateText()
if bonusCoins.Value ~= 0 or nil then
textLabel.Text = bonusCoins.Value
else
textLabel.Text = 0
end
end
bonusCoins:GetPropertyChangedSignal("Value"):Connect(function()
updateText() -- Update as the value changes
end)
updateText()
Yeah I’m looking into that now. Not 100% sure whether the if/then statements stay where they are or if they go into a server script and the client just fires the OnServerEvent or not.
I do not think you will need to detect things on the client as exploiters do exist, but I’m certain you can just change those if statements server sided.
local player = game.Players.LocalPlayer
local playerstats = player:WaitForChild("playerstats")
local bonusCoins = playerstats.BonusCoins
local rebirthToken = playerstats.RebirthToken
local upButton = game.PlayerGui.StatsGui.Frame.InnerFrame.CoinsText.UpButton
local downButton = game.PlayerGui.StatsGui.Frame.InnerFrame.CoinsText.DownButton
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local function upButton()
-- some code
end
local function downButton()
-- some code
end
remoteEvent.OnServerEvent:Connect(upButton)
remoteEvent.OnServerEvent:Connect(downButton)
Having the same remote event connected to downButton will disconnect the connection to upButton connection.
Also, the client should NEVER be making changes to how much coins they have, the server should. When the client presses a button, fire a remote event for the server to change that and add coins, only on click. And the server should simply replicate the values to the client, via a leaderstats folder value or some other way of replicating values.
TLDR: I highly highly recommend you to not put your data saving/ setting/ managing scripts anywhere but in ServerScriptService, for security reasons.
Yep it is in the ServerScriptService as you can see from the error. The GUI in question is in StarterGui (Which I believer gets cloned to each connected player into PlayerGui) so no issues there. Your remote event comment is helpful but I’m having trouble calling the playerstats (a folder in the same location as the leaderstats folder, player.LocalPlayer.playerstats). Usually you waitforchild() but in this case it says infinite yeild possible in the output window and when I play around with it I get errors. “ServerScriptService.PlayerStatsScript:2: attempt to index nil with ‘WaitForChild’”