Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

FireServer from local script help?

Works in studio, not in play

I'm trying to get it so it will send the text and it can receive it, but I'm extremely lost and keep getting the error: 'OnServerEvent can only be used on the server line 7'

Everything I try just leads to an error

--sendr
script.Parent.EditFrame.Enter.MouseButton1Down:connect(function()
	game.Workspace.DisplayManger.Sender:FireServer(script.Parent.EditFrame.TextBox.Text)
end)

--recivr
game.Workspace.DisplayManger.Sender.OnServerEvent:connect(function(player, text)
	script.Parent.TextLabel.Text = "The party is at: "..text
end)

1 answer

Make sure the script calling :FireServer() is a localscript and the script getting the .OnServerEvent is a serverscript.

-- Localscript
repeat game:GetService'RunService'.RenderStepped:wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer
local gui = script.Parent

gui.EditFrame.Enter.MouseButton1Down:connect(function()
	game:GetService'Workspace':WaitForChild'DisplayManger'.Sender:FireServer(gui.EditFrame.Text)
end)

-- ServerScript
game:GetService'Workspace'.DisplayManger.Sender.OnServerEvent:connect(function(player,text)
	script.Parent.TextLabel.Text = "The party is at: "..text
end)




This discussion is preserved as it was. New answers, comments, and votes are closed.