It can more than one time click but I want let the text everytime change when I press Mouse Button1Down. So it should be like that: 50 + 70 + 90. The thing is that it will be everytime +20
I just want know how I can click more than one time. Its better if you start the game because it is really hard to send everything here.
But if you want just see the Mouse script here (but the reason is something else I cant see it maybe my Gui):
This is the LocalScript:
local player = game.Players.LocalPlayer
local rp = game:GetService("ReplicatedStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")
local G = replicatedStorage:WaitForChild("Goldclick")
local Mouse = player:GetMouse()
Mouse.Button1Down:Connect(function()
G:FireServer()
end)
This is the gui Script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local Goldclick = replicatedStorage:WaitForChild("Goldclick")
local Goldchange = script.Parent.Frame.Goldname
Goldclick.OnServerEvent:Connect(function(player)
local Data = player.Data
local GoldData = Data:WaitForChild("Gold")
local newvalue = GoldData.Value
Goldchange.Text = newvalue + 20
end)
Your game is all wrong, why are you using a server script in the gui? Why are you making two variables for ReplicatedStorage? Why are you trying to get the player’s data through “player.Data”?? You need to seriously organize your game, as for your issue, even though I can barely understand what you’re trying to say, you need to first get a hold of what everything does, eg. Button1Down will always trigger when the player clicks, not just when they click the button. Please clean up your game and make sure people can actually understand your question.
I am not creating a game I am just testing stuff! What you trying is to explain my problem better.
Again for you: I want make my Gui Text more than one time +20 - when the player clicks many times it should get the times of +20 for the value in the text. Like when I have 50 then I click + 20 it should be 70. When I click again it should be +20.
This is event not for organize everyhting. Just testing stuff out???
“player.Data” is not a valid property of a player, you also need to change your gui scripts, use one local script in the gui that detects a click and fires an event, and the server handles the data
local DataStorage = game:GetService("DataStoreService")
local PlayerData = DataStorage:GetDataStore("playerGold")
game.Players.PlayerAdded:Connect(function(player)
local playerFolder = Instance.new("Folder", player)
playerFolder.Name = "Data"
local Gold = Instance.new("IntValue", playerFolder)
Gold.Value = 50
Gold.Name = "Gold"
local Silver = Instance.new("IntValue", playerFolder)
Silver.Value = 1000
Silver.Name = ""
local data
local key = "Player_"..player.UserId
local sucess, errormessage = pcall(function()
data = DataStorage:GetAsync(key)
end)
if sucess then
Gold.Value = data
elseif data == nil then
print("gold has been saved")
else
print("error saving data, error saving data!!")
warn(errormessage)
end
end)
TigerLeo77 look. I created that for changing the value in it. So we dont talk about the player properties. I just wanted change the Gold Value of the player when he clicks MouseButton. And everyone knows that you can organize your script unlimited.
Again for you because I dont think you understood my question. I want change the value of the gold when I click with my Mouse. And everytime when I click the gold value should increase to +20???
For me, it hasnt updated a single time, if you want a working money system that saves, you cant just change the text of some element (Goldchange.Text = newvalue + 20) to save it, you should fire an event to the server which then updates the data store. You also need to stop using server scripts in the gui, as they wont have an effect for the local player. You can just change the script you have in the gui to be a local script and fire an event everytime the button is clicked - goldButton.MouseButton1Click:Connect(yourFunction), then have the server change the data store (also update the text with said local script)
No it doesnt seem work. And why do you help me. It seems like a lot of people listen to this problem. Your explanation is tricky because I did what you say still not work…
I am sorry, but for you as a programmer. Next time you could just go on the problem. And also for you the problem was just to put a local script in the “OnServerEvent” you did it so complicated for me.
I solved it. And it was just one thing you could write here. Thanks for your help but your explanation was 0% helpfull in my opinion. - take it as a feedback - no hate!
Hello! I know you already fixed it but I recommend watching Alvin Blox video about DataStores as he explains it in a very simple way and It’ll probably help you