I wanted to make a system, that requires a setup from the admin panel.
It is supposed to work like, an admin puts a number, which goes to the value, and it should be on the whole server, so I wanted to make a text that admin put visible for all users, but it did not work.
I tried server script, but it didn’t work since some functions should work in a local script, in a local script fuctions that should work in a normal script did not work.
I think I made a mistake in placing the script or something, here is the script.
–First create a RemoteEvent in ReplicatedStorage then:
–Client:
local textBox = … – Where your TextBox is
local textButton = … – Where your TextButton is
This is not working due to the fact you’re not using the Player parameter once listening to OnServerEvent (Mentioned by @bleintant) and you’re defining a string’s Text property - Which is not possible due to the fact strings don’t have one. (Mentioned by @Prespective_Broken)
The fix for this is to define your variables on the right way, define the TextBox’s text only if the Text is valid - On this case, If it’s an actual text and it has atleast 1 character or more and use the TextBox object instead of an actual string.
-- Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChangeTextbox = ReplicatedStorage:WaitForChild("ChangeTextbox")
-- Listen to `ChangeTextbox` and fire back to all Clients.
ChangeTextbox.OnServerEvent:Connect(function(Player: Player, TextReceived: string)
local IsValidText = TextReceived ~= nil and type(TextReceived) == "string"
if not IsValidText then
return
end
print("[Server] - Received text! Updating new Text to all Clients:", TextReceived)
ChangeTextbox:FireAllClients(TextReceived)
end)
-- Client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChangeTextbox = ReplicatedStorage:WaitForChild("ChangeTextbox")
-- Replace those with the paths for your Instances.
local TextButton = script.Parent:WaitForChild("TextButton")
local TextBox = script.Parent:WaitForChild("TextBox")
-- Listen to whenever the Button gets fired.
TextButton.Activated:Connect(function()
local Text = tostring(TextBox.Text)
local Length = Text and string.len(Text)
local IsValidLength = Length and Length > 0
if not IsValidLength then
return
end
-- It's not really recommended to fire strings into the Server;
-- ... as they would cost some Networking bits/data.
ChangeTextbox:FireServer(Text)
end)
-- Update `TextButton` once `ChangeTextbox` is fired to the Client.
ChangeTextbox.OnClientEvent:Connect(function(TextReceived: string)
local IsValidText = TextReceived ~= nil and type(TextReceived) == "string"
if not IsValidText then
return
end
print("[Client] - Updating Local TextBox's Text to:", TextReceived)
TextBox.Text = TextReceived
end)