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

How do i fix onserverevent thing?

Asked by 5 years ago
local rstorage = game:GetService("ReplicatedStorage")

local event = rstorage:WaitForChild("OBJChanged")

event.OnServerEvent:Connect(function()
    event.Objective.Value = script.Parent.OBJText.Text
end)

OnServerEvent can only be used on the server Script 'Players.SunxLightz.PlayerGui.OBJGui.OBJ', Line 5

How do i fix this, i wanna make this show to every player

Objective gui when touches part fires event, if event fired in local script inside gui, the text changes

0
Learn how to read User#24403 69 — 5y
0
It is telling you the error, so use common sense (the best solution to all problems, even ones outside of programming) to fix it User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

Well....... You are using .OnServerEvent in a local script, that's obvious.. You even answerd yourself, and the error shown is very easily comprehinsable. Always check your script carefully!

Now I guess you did this because in your server script youc ant refer to the LocalPlayer. Now isn't that just perfect! Your :FireServer function which is going to be inside your local script can also send to the server any given paramater. That's so helpful and the exact solution for your problem. Always use it.

Now let me explain what Is said

-This is your local script

local player = game.Players.LocalPlayer -- this is the player, which can only be refered to locally
local number = 72 -- this is a variable that were gonna use for testing

local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

remote:FireServer(player, number)
-- now you see i put our two variables in there as our 2 arguments, and were gonna send those into our server script, and like that we have access to the player, and also the number value

--Your server script

local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
-- now remember that the server and client and that you want to make contact with eachother have to use the same rémote event!

remote.OnServerEvent:Connect(function(player, number) 
    print(player, number) -- it will print them succefully! Now see what I did? i put in the same                
        arguments that i put in the local script! and now you got access to player and 72, i ho^pe 
        you got the idea, and remember that this event will fire when :FireServer did its thing.
end)

Im glad that i helped, and i hope you understood how remote events work. More Information!

Ad

Answer this question