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

Why does String Value doesn't want to change it's Value from local script from StarterGui?

I really don't know why does this script don't changes the String Value in Workspace. Here is the script, if you have any suggestions about this question make sure to leave a comment down there, you are going to help me a lot, and if you help me, I am going to accept your answer!

Script:

local Database = game.Workspace.Level_Database
local UsernameValue = Database.Username

local UsernameBox = script.Parent
local ScreenGui = script.Parent.Parent.Parent

function onClicked()
	UsernameBox.Text = UsernameValue.Value
	wait(0.1)
	ScreenGui.Enabled = false
end

script.Parent.MouseButton1Click:connect(onClicked)

2 comments

0

You cant enable a screen gui from a server script

0

Well, joeldes that is not the problem, only problem here is that the script wont change the StringValue from TextBox!

2 answers

Hey there.

As others have mentioned, you cannot communicate between the client and server directly with FilteringEnabled turned on.

To get past this, you should use a RemoteEvent sending information from the LocalScript to a Script.

Here is some example code, but check out the links at the bottom of my answer for more in-depth learning.

Client:

local rep = game:GetService("ReplicatedStorage")
local sendName = rep:WaitForChild("SendName")
--Place a "RemoteEvent" in ReplicatedStorage called "SendName"

local usernameBox = script.Parent
local screenGui = usernameBox.Parent.Parent

function click()
	screenGui.Enabled = false
	sendName:FireServer(usernameBox.Text)
end

usernameBox.MouseButton1Click:Connect(click)

Server:

local rep = game:GetService("ReplicatedStorage")
local sendName = rep:WaitForChild("SendName")

local database = game.Workspce.Level_Database
local usernameVal = Database.Username

sendName.OnServerEvent:Connect(function(player, text)
	usernameVal.Value = text
end)

I believe your problem lies in the fact that you're attempting to enable a ScreenGui using a server script. With FE on, you can not modify ScreenGuis with server scripts. Try copying your code into a local script.

Also, I would just like to suggest that you use :Connect() rather than :connect(), as it is deprecated.

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