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

How do I fire a client event?

Asked by 6 years ago

In server scripts you can't do this:

local plr = game.Players.LocalPlayer

How would I fire a client event if I can't use that? I want to fire a client event without a function that gets the local player such as player entering, player removing, etc

I tried to do this before but it didn't let me.

1 answer

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

Well, if you want to get the player in the server using RemoteEvents without using functions like that, I guess you can do something like this :

Local script:

local plr = game.Players.LocalPlayer
local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent in ReplicatedStorage

event:FireServer(plr)

Server script:

local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent in ReplicatedStorage
local player -- Variable to save "plr"

event.OnServerEvent:Connect(function(plr)
    print(plr)
    player = plr
end)

As soon as the local script runs those lines of code, it'll fire the LocalPlayer using a RemoteEvent in ReplicatedStorage. The server script then detects the fire, gets the LocalPlayer, then saves it in the "player" variable. You'll then be able to mess around with the player and etc.

Hope this helped!

Ad

Answer this question