Answered by
4 years ago Edited 4 years ago
It is not being saved because you are changing the value on the client, and the server doesn't see the change. What you should do is use a RemoteEvent to change it on the server. Here's how you set it up:
05 | local chooseEvent = game.ReplicatedStorage:WaitForChild( "changeChoose" ) |
07 | script.Parent.Text = "Not Pressed Yet!" |
09 | script.Parent.MouseButton 1 Click:Connect( function () |
11 | if Choose.Value = = false then |
13 | script.Parent.Text = "True" |
14 | chooseEvent:FireServer( true ) |
16 | elseif Choose.Value = = true then |
18 | script.Parent.Text = "False" |
19 | chooseEvent:FireServer( false ) |
27 | local DataStore = game:GetService( "DataStoreService" ) |
28 | local GetData = DataStore:GetDataStore( "ValueDataStore" ) |
29 | local Choose = game.ReplicatedStorage.Choose |
30 | local chooseEvent = game.ReplicatedStorage.changeChoose |
32 | game.Players.PlayerAdded:Connect( function (player) |
36 | local Success, error = pcall ( function () |
38 | data = GetData:GetAsync(player.UserId) |
55 | game.Players.PlayerRemoving:Connect( function (player) |
57 | GetData:SetAsync(player.UserId,Choose.Value) |
65 | chooseEvent.OnServerEvent:Connect( function (player,status) |
Remember exploiters can fire the remote and change it to false or true whenever they want, so depending on what you're doing you will be able to secure the remote. Edit: it was saying SetAsync was not a valid member of DataStoreService because you have to do it on the actual datastore, not the service. I've fixed the script.