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

FireServer from local script help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

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

Log in to vote
3
Answered by
4Bros 550 Moderation Voter
8 years ago

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)




Ad

Answer this question