My script isn’t working, sorry for the uninformative title, but why isn’t this working, when you hit the SurfaceGui Button it should give you cash, but it doesn’t
Nope, if it’s on the client it won’t replicate to the server, meaning that it’s essentially useless. That 1000 cash will only be seen by the local player on that server
Local scripts only work for the client (this is with filtering enabled on). Changes made from the client on the server do not show for any other players, or the server itself.
I think as soon as you mentioned surfacegui, i believe i know what is wrong with it. When you’re making clickable buttons with a surface gui, you have to make sure that the surface gui is inside your playergui and adornee’d to the part that it’s currently on, this means that you can click on the button.
Also, please do make sure that you consider moving your money transfers over to server side as newer tycoons won’t be able to acknowledge that you actually received 1000 money. For this, you would have to make a remote event.
People, please do your research and testing before posting. OP please also do research and make sure to debug your code and check the console for errors. All of you are still missing a fundamental piece collectively making your responses incorrect: players are not fired as an argument of MouseButton1Click. You need a RemoteEvent that the client can fire upon clicking the button and the server needs to process that request then add currency to the user.
Depends if the script is on the client or server side - if it’s on the server side (workspace, serverscriptservice etc) then a remote event isn’t needed
You never should control a Gui from a Script so that’s out of the question entirely. If you want to architecture your game properly, LocalScripts should be handling client-side input and the server should be receiving requests from the server to authoritatively change information. So yes you do need a remote if you’re looking to do this properly.
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
local part = game.Workspace.Part
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("GiveBasicCash")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Money"
Cash.Value = ds:GetAsync(player.UserId) or 5000
ds:SetAsync(player.UserId, Cash.Value)
while true do
wait(2)
ds:SetAsync(player.UserId, Cash.Value)
end
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)
game.Workspace.BasicDice.SurfaceGui.TextButton.MouseButton1Click:Connect(function(plr)
local Cash = plr:FindFirstChild("leaderstats").Money
Cash.Value = Cash.Value + 1000
end)
This is my full script, the leaderstats aren’t showing anymore.