As in my recent article, I found out that I needed to provide a variable. Now, I decided to convert the script into a localscript in an icon, located in the frame. I may not understand FireClient() as intended, but I’m seeking assistance into a solution for this. Here’s my code:
-- In the "Icon" imagebutton
local rep = game.ReplicatedStorage.SetIcon
rep.OnClientEvent:Connect(function(plr, txt)
print("User has typed "..txt.." in the textbox!")
end)
-- In the "Submit" button
local rep = game.ReplicatedStorage.SetIcon
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
rep:FireClient(plr, script.Parent.Parent.TextBox.Text)
end)
What’s the concurrent issue that creates that specific error? If possible to elaborate on, I’d appreciate it.
FireClient() may only be called in a server script, and you’re calling it from a LocalScript. Replace FireClient() with FireServer() and get rid of the player argument in it.
The thing is, when I change it into “FireClient”, it won’t pop up as the other script has “OnServerEvent”, producing an error of “OnServerEvent can only be used on the server”
Considering these are both local scripts you can combine them into one script and put it under icon and remove the remote event entirely
-- in the "Icon" image button
local function SetIcon(txt)
print("User has typed "..txt.." in the textbox!")
end
script.Parent.Submit.Activated:Connect(function()
SetIcon(script.Parent.TextBox.Text)
end)