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

My RemoteEvent (Client to Server) won't work, what's wrong with my scripts?

Asked by 3 years ago
Edited 3 years ago

Local Script:

(When a button is pressed, a Screen Gui I have will close btw, and I added the RemoteEvent to do something in the Server once Gui closes.)

local opened = script.Parent.Parent
local close = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RE1")

close.MouseButton1Up:Connect(function()
    opened:TweenPosition(
        UDim2.new(0.32, 0,-0.771, 0),
        "Out",
        "Quad",
        1,
        false
    )
    local theTextYouWantToMove = game.StarterGui.AgendaGUI.AgendaFrame.AgendaTxt
    remoteEvent:FireServer(theTextYouWantToMove.Text) 
end)

Script in (ServerScriptService):

(When someone types in something in a textbox, i want whatever they typed to be the new text in a part in workspace)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RE1")


local function ChangeText(player, text)
    local NAText = workspace.Agenda.Agenda.SurfaceGui.NA
    NAText.Text = text
end

remoteEvent.OnServerEvent:Connect(ChangeText)

Btw I used the RemoteEvent scripts from the Roblox Dev Website and followed the steps but for some reason what I am doing is not working. Please help!

0
um for the top script there is no input parameter, it just fires the server it doesnt have the text string AlexanderYar 788 — 3y
0
Try printing theTextYouWantToMove.Text and confirm you're sending a string through. DinozCreates 1070 — 3y
0
i wrote: "print("theTextYouWantToMove.Text") in server script, in line 9... the output said: theTextYouWantToMove.Text mettle56 17 — 3y
0
Dont put it inside of quotes. DinozCreates 1070 — 3y
0
HEY PPL, I'm so happy I finally found my problem, I referenced the text as "StarterGui" and realized you can't do that and need to say script.Parent.ETC! It worked. mettle56 17 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

um for the top script there is no input parameter, it just fires the server it doesnt have the text string, also when you did the connect function, you only have 1 parameter you also need to include the player parameter i think, so it should be

1.

local opened = script.Parent.Parent
local close = script.Parent

close.MouseButton1Up:Connect(function()
    opened:TweenPosition(
        UDim2.new(0.32, 0,-0.771, 0),
        "Out",
        "Quad",
        1,
        false
    )

local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local remoteEvent = ReplicatedStorage:WaitForChild("RE1")
    remoteEvent:FireServer(gui.Text)
end)

2.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RE1")


local function ChangeText(player, NAText)

    local NAText = game.Workspace.Agenda.Agenda.SurfaceGui.NA.Text

    NAText = game.StarterGui.AgendaGUI.AgendaFrame.AgendaTxt

end

remoteEvent.OnServerEvent:Connect(plr, ChangeText)

actually i might have misunderstood this, i see another problem that i think is what you meant, when you connected, you didnt connect to the function, you jsut wrote :CONNECT and then the parameters, theres no function there, so it should be something like this:

2.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RE1")


local function ChangeText(player, NAText)

    local NAText = game.Workspace.Agenda.Agenda.SurfaceGui.NA.Text

    NAText = game.StarterGui.AgendaGUI.AgendaFrame.AgendaTxt

end

remoteEvent.OnServerEvent:Connect( ChangeText(player_, NAText_) )

although i dont like making a function and calling it in a different line, so i prefer this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RE1")




remoteEvent.OnServerEvent:Connect(function(player, NAText)

    local NAText = game.Workspace.Agenda.Agenda.SurfaceGui.NA.Text

    NAText = game.StarterGui.AgendaGUI.AgendaFrame.AgendaTxt

end)
0
ok thanks for accepting my answer :3 AlexanderYar 788 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

Okay! I moved the variables because its ugly to create a new local for every connection if not needed. The localplayer is automatically passed when firing to the server so its unnecessary to add it, just pass the text.

local opened = script.Parent.Parent
local close = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RE1")

close.MouseButton1Up:Connect(function()
    opened:TweenPosition(
        UDim2.new(0.32, 0,-0.771, 0),
        "Out",
        "Quad",
        1,
        false
    )
    local theTextYouWantToMove = reference.it.here -- never add an objects value at the end of a variable, add the object itself and then reference the value later
    remoteEvent:FireServer(theTextYouWantToMove.Text) --here we pass the text as 'object.value', Text in this instance
end)

On here, we have the same issue with you trying to store an objects value in a variable, dont do! Also you attempted to pass 'NAText' as a parameter and then proceed to set its value, why pass it if you just want to change it?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RE1")


local function ChangeText(player, thePassedText)
    local NAText = workspace.Agenda.Agenda.SurfaceGui.NA -- a little trick here, just use workspace.X not game.Workspace :)
    NAText.Text = thePassedText -- we set the workspace surface to the value passed through the event, easy!
end

remoteEvent.OnServerEvent:Connect(ChangeText)
0
Ohhh, ty lol! mettle56 17 — 3y
0
I upvoted thanks for posting this AlexanderYar 788 — 3y
0
There's a problem, when I type in the textbox and press close, and the text of the part just turns into nothing, and doesnt write what i put in the textbox mettle56 17 — 3y
0
You'll have to edit your post with the updated code for me to assist. DinozCreates 1070 — 3y
View all comments (4 more)
0
Ok I updated it mettle56 17 — 3y
0
i wrote: "print("theTextYouWantToMove.Text") in server script, in line 9... the output said: theTextYouWantToMove.Text mettle56 17 — 3y
0
Ohh i forgot but i did and it said this: ServerScriptService.ChangingText:10: attempt to index nil with 'Text' and it underlines "theTextYouWantToMove" blue in script, so does that mean nothing got sent? mettle56 17 — 3y
0
Thats correct, the text is empty. DinozCreates 1070 — 3y

Answer this question