Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do i save TextBox info to a server?

Asked by 4 years ago

This is probably a very silly question that is easy to solve, but i have looked for hours and have been unable to solve my problem. I would like to be able to take a user input (into my text box) and save the input onto a server, datastore would be the obvious one but I have tried getting this to work and it did not work. My method was to create a variable:

 SERVERINFO = TextBox.Text 

and use that variable to save information to the server but it has not seemed to work. Any help would be greatly appreciated!

Many thanks :)

0
If you want it simplified to the bare minimum, you would use _G to create a global variable for all ServerScripts to have access to. So, it'd be _G.WhatEverYouWant = TextBox.Text killerbrenden 1537 — 4y
0
^ That won't save whenever the player leaves, but will always be that while the player is still in the game. killerbrenden 1537 — 4y
0
HeavenlyBlobmaster has a really good answer! Also, you can use a datastore to save data before it gets overwritten using a global-function i believe is called PropertiesChanged Heavenlyblobmaster 271 — 4y
0
This is a request so downvoted my man St_vnC 330 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

there are several ways you can do this. you need a value in the workspace representing what you need to save. Here is the easiest: in a script

local function createEvent(eventName)
    local event = game.ReplicatedStorage:FindFirstChild(eventName)
    if not event then
        event = Instance.new("RemoteEvent", game.ReplicatedStorage)
        event.Name = eventName
    end
    return event
end

local save= createEvent("savedata")

save.OnServerEvent:Connect(function(player, newboxdata)
local hh = workspace:FindFirstChild("YourValueName")
hh.Value = newboxdata

And in a local script:

function lmbo()
local xb = script.Parent.Parent.TextBox
game.ReplicatedStorage:FindFirstChild("savedata"):FireServer(xb.Text)
end
script.Parent.Activated:Connect(lmbo)

The localscript will be in the button, and the text you want saved will be in the textbox. This will update the server on the text in that player's box, but will not update any other clients. It can also be overwritten by other clients. If this isn't what you intended, tell me and i will help you more. See ya!

0
You can grab the data with a datastore befor it gets overwritten. I can help you with that to. This response is really good. Heavenlyblobmaster 271 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You could do that, or you could do this:

--Client
local RS = game:GetService("ReplicatedStorage")
local TextEvent = ReplicatedStorage:WaitForChild("textEvent")
--when the player inputs text
TextEvent:fireServer(TextBox.Text)
--Server
local DSS = game:GetService("DataStoreService")
DataStore = DSS:getDataStore("TextInfo")
local RS = game:GetService("ReplicatedStorage")
local TextEvent = Instance.new("RemoteEvent", RS)
TextEvent.name = "textEvent"
local function onTextRecived(player, text) -- need the player because client automatically adds it in
    print(player.." send this text: "..text)
    DataStore:SetAsync(player, text) -- I know you said no Data Store, but maybe you were using it wrong? if not just substitute this for the comment
end
TextEvent.OnServerEvent:connect(onTextRecived)

This might solve your problem if not, use the comments

Answer this question