Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change datastore data from a local gui script?

I have a script attached to a button attached to the Starter Gui. When a player joins, he gets his own gui with his own button and script. In that script I'm trying to change DataStore variable (that is stored in a folder in each player) but I don't know how. I'm trying to directly change the variable with the button script and it says I've done so, but the ServerScriptService script doesn't detect the change. If you have any questions, please ask.

game.Players.LocalPlayer.data.has_done_intro.Value = true

This is how I change the bool variable that's located in Player > "" > data > has_done_intro. And indeed the variable does change (in the Studio) but the server doesn't seem to detect that at all. It's like the server doesn't detect any changes that aren't made by him.

2 comments

0

This is how the game is supposed to act. Trust nothing of the client where data does not get replicated to the server and everyone else. You'll want to look into RemoteEvents in order to change values on the server side.

0

Thanks! That's exactly what I'm doing now, figured it out on my own :P

2 answers

✓ Accepted answer

You must use a RemoteEvent. These handy objects will allow you to replicate value changing to the server (basically make the server detect the change)

This script must be a LocalScript.

local RepStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = RepStorage:WaitForChild("EVENTNAMEHERE")
local gui = script.Parent
local button = gui.Button

button.MouseButton1Click:Connect(function()
RemoteEvent:FireServer()
end)

Then the ServerScript:

local RepStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = RepStorage:WaitForChild("EVENTNAMEHERE")

RemoteEvent.OnServerEvent:Connect(function(player)
player.data.has_done_intro.Value = true
end)

What's going on? When the button is clicked, the RemoteEvent asks the server to change the value. In the ServerScript, that answer will always be "yes" (unless you implement something that returns false).

I hope this helped you! Please mark this question as "Accepted" if it helped.

If you'd like to know more, you can check out the Wiki page for RemoteEvents/Functions: Wiki page

1 comment

0

I love you!

This is because of filtering enabled. Filtering enabled is a system that roblox put in all games to prevent hackers. In short filtering enabled does this: there are 2 sides to the game, server side and client side(client side is your computer and what you see) both of theese are different games. The difference is that client side cannot send things to the server but the server can. You can use something called a remote even to get around this

This discussion is preserved as it was. New answers, comments, and votes are closed.