Hi, I'm currently testing a prototype for a custom chat using a text box, scripts and a text label. It doesn't display a error, but when I press enter, the script doesn't work and the text doesn't appear. I am currently on my MacBook, so I can't show any gifs but here's the scripts.
LocalScript:
01 | local userInput = game:GetService( "UserInputService" ) |
02 |
03 | userInput.InputBegan:Connect( function (input) |
04 | if input.KeyCode = = Enum.KeyCode.Return then |
05 | if script.Parent.TextBox.Text = = "" then |
06 | else |
07 | local text = script.Parent.TextBox.Text |
08 | game.ReplicatedStorage.chatFunction:FireServer(text) |
09 | script.Parent.TextBox.Text = "" |
10 | end |
11 | end |
12 | end ) |
Script:
01 | local function Chat(text) |
02 | local CloneText = script.Parent.TextLabel:Clone() |
03 | CloneText.Visible = true |
04 | CloneText.Text = text |
05 | if CloneText ~ = nil then |
06 | if CloneText.Position = = UDim 2. new( 0.1 , 0 , 0.65 , 0 ) then |
07 | CloneText.Position = CloneText.Position - UDim 2. new( 0 , 0 , 1 , 0 ) |
08 | else |
09 | CloneText.Position = UDim 2. new( 0.1 , 0 , 0.65 , 0 ) |
10 | end |
11 | end |
12 | end |
13 |
14 | game.ReplicatedStorage.chatFunction.OnServerEvent(Chat) |
sry for bad english
Try this out : (Maybe you need to edit it)
--Server Script:
01 | game.ReplicatedStorage.chatFunction.OnServerEvent:Connect( function (plr,text) |
02 | local CloneText = script.Parent.TextLabel:Clone() |
03 | CloneText.Visible = true |
04 | CloneText.Text = text |
05 | if CloneText ~ = nil then |
06 | if CloneText.Position = = UDim 2. new( 0.1 , 0 , 0.65 , 0 ) then |
07 | CloneText.Position = CloneText.Position - UDim 2. new( 0 , 0 , 1 , 0 ) |
08 | else |
09 | CloneText.Position = UDim 2. new( 0.1 , 0 , 0.65 , 0 ) |
10 | end |
11 | end |
12 | end ) |
the functions connected to OnServerEvent
will be passed the player
who fired the event as the first parameter.
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events