EOASTUDIO
(EOASTUDIO)
April 13, 2022, 6:10am
#1
I have a script:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local ValueFolder = Instance.new("Folder")
ValueFolder.Name = "ValueFolder"
local ValueNickname = Instance.new("StringValue")
ValueNickname.Name = "Nickname"
ValueNickname.Value = Player.DisplayName
ValueNickname.Parent = ValueFolder
ValueFolder.Parent = Player
end)
and I want to make the Value = Text written in a textbox.
How should I change my code to make it do so?
Vaschex
(Vaschex)
April 13, 2022, 6:29am
#2
The Text property represents the content of the TextBox. Therefore you can set the ValueNickname.Value
property to TextBox.Text
when the FocusLost event fires.
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 6:34am
#3
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local ValueFolder = Instance.new("Folder")
ValueFolder.Name = "ValueFolder"
local ValueNickname = Instance.new("StringValue")
ValueNickname.Name = "Nickname"
ValueNickname.Value = Player.PlayerGui.ScreenGui.Frame.NicknameFrame.NicknameBox.Text
ValueNickname.Parent = ValueFolder
ValueFolder.Parent = Player
end)
Like this?
Vaschex
(Vaschex)
April 13, 2022, 6:41am
#4
Yes, that would set the nickname once. But I guess you want it to be set when the player types something new in the TextBox.
The FocusLost event fires when the player presses Enter for example or generally is done typing. You should connect a function to this event which updates the StringValue.
Vaschex
(Vaschex)
April 13, 2022, 6:43am
#5
By the way, is that in a Script? This has to be in a LocalScript.
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 6:43am
#6
Yes exactly, but there is no apply edits button
Could u script it for me or tell me what I should add pls
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 6:44am
#7
It’s in a script in ServerScriptService
Vaschex
(Vaschex)
April 13, 2022, 6:45am
#8
local textBox = ...
textBox.FocusLost:Connect(function()
ValueNickname.Value = textBox.Text
end)
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 6:46am
#9
I should add this in what part of my script?
Vaschex
(Vaschex)
April 13, 2022, 6:46am
#10
In that case you need to fire a RemoteEvent from the client to the server.
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 6:47am
#11
I’ll change it to LocalScript.
Where should the LocalScript be stored?
Vaschex
(Vaschex)
April 13, 2022, 6:54am
#12
Create a RemoteEvent in ReplicatedStorage.
LocalScript in StarterGui:
local updateEvent = ...
local textBox = ...
textBox.FocusLost:Connect(function()
updateEvent:FireServer(textBox.Text)
end)
Script in ServerScriptService:
local Players = game:GetService("Players")
local updateEvent = ...
Players.PlayerAdded:Connect(function(Player)
local ValueFolder = Instance.new("Folder")
ValueFolder.Name = "ValueFolder"
local ValueNickname = Instance.new("StringValue")
ValueNickname.Name = "Nickname"
ValueNickname.Value = Player.DisplayName
ValueNickname.Parent = ValueFolder
ValueFolder.Parent = Player
end)
updateEvent.OnServerEvent:Connect(function(Player, Text)
Player.ValueFolder.Nickname.Value = Text
end)
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 7:04am
#13
My friend tried it while I was still fixing some GUI’s and it doesn’t work, this comes in the output:
They are providing you sufficient code. Make sure to change the variable values to objects of your own.
EOASTUDIO
(EOASTUDIO)
April 13, 2022, 7:40am
#15
So i should change updateEvent to the name of my remoteevent
and change textBox to the name of my textbox?
Yes change the variables to your directories.
1 Like