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

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

Asked by 6 years ago

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)
0
You cant enable a screen gui from a server script joeldes 201 — 6y
0
Well, joeldes that is not the problem, only problem here is that the script wont change the StringValue from TextBox! AswormeDorijan111 531 — 6y

2 answers

Log in to vote
2
Answered by
amanda 1059 Moderation Voter
6 years ago

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)
Ad
Log in to vote
1
Answered by
oreoollie 649 Moderation Voter
6 years ago

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.

Answer this question