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

How to connect a RemoteEvent?

Asked by 3 years ago

Hello! I am making a game and I wanna know how to connect a RemoteEvent so everyone can see the effect for the attack I am creating.

Script:

local player = game.Players.LocalPlayer
local character = script.Parent
local remoteEvent = game.ReplicatedStorage:WaitForChild("forcebrr")
local UserInputService = game:GetService("UserInputService")
local requiredKey = Enum.KeyCode.R
local rStorage = game.ReplicatedStorage

UserInputService.InputBegan:Connect(function(key, gameProcessed)
    if key.KeyCode == requiredKey then
        --Part Creation, won't waste your time here.
    end
end)

I need to know how to bind the event and make it so everyone can see it.

3 answers

Log in to vote
0
Answered by 3 years ago

If you need the part creation, this is it:

local part = game.ServerStorage.ForceField:Clone()
        part.Parent = workspace
        part.Position = character.Torso.Position
        part.CanCollide = true
        part.Anchored = true
        wait(0.01)
        part.Size = Vector3.new(5.5, 5.5, 5.5)
        part.Transparency = 0.1
        wait(0.01)
        part.Size = Vector3.new(8, 8, 8)
        part.Transparency = 0.2
        wait(0.01)
        part.Size = Vector3.new(10.5, 10.5, 10.5)
        part.Transparency = 0.3
        wait(0.01)
        part.Size = Vector3.new(12.5, 12.5, 12.5)
        part.Transparency = 0.4
        wait(0.01)
        part.Size = Vector3.new(14.5, 14.5, 14.5)
        part.Transparency = 0.5
        wait(0.01)
        part.Size = Vector3.new(16, 16, 16)
        part.Transparency = 0.6
        wait(0.01)
        part.Size = Vector3.new(17.5, 17.5, 17.5)
        part.Transparency = 0.7
        wait(0.01)
        part.Size = Vector3.new(18.5, 18.5, 18.5)
        part.Transparency = 0.8
        wait(0.01)
        part.Size = Vector3.new(19, 19, 19)
        part.Transparency = 0.9
        wait(0.01)
        part.Size = Vector3.new(19.5, 19.5, 19.5)
        part.Transparency = 0.95
        wait(0.01)
        part:Destroy()
        wait(10)
Ad
Log in to vote
0
Answered by 3 years ago

Looks like you already have the event so I won't waste your time telling you where to put it.

To begin with, when an event is fired from the server it goes to the client Script -> LocalScript. That being said, when fired from the client it goes to the server LocalScript -> Script.

Judging by line 1 I am guessing that this is a localscript, so what you need to do is fire the event from the client and pick it up on a separate and server sided script. Just remember, localscripts only run on the client and nobody else can see the effects of them, while normal scripts run on the server where everyone can see.

The line of code you'll need for the localscript posted: remoteEvent:FireServer()

-- Explanation: -- When you fire to the server, you can pass certain variables through, but the simple thing I forget to add all the time when teaching people about events, is the fact that the player is ALREADY being passed by default, and does not to be put in manually.

The line of code you'll need for the server script, where you should place all code: game.ReplicatedStorage.forcebrr.OnServerEvent:Connect(function(Player)

-- Explanation: -- (Keep in mind there are a few flaws I will point out now) In the above line I did not include a end), so please apply that. Any code in the server script, when inside that function, will run for every player to see when the event is fired from the client.

If you have any questions or concerns comment, if this helped or worked accept my answer. Have a great day!

Log in to vote
0
Answered by 3 years ago

The code is in a localScript, so it will not be seen by other players except you, so to connect it with a RemoteEvent.

You can create a RemoteEvent within ReplicatedStorage, and a script in ServerScriptService. To activate the RemoteEvent, put the following props in your code.

local ReplicatedStorage =  game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

 -- Now inside your function.

RemoteEvent:FireServer() -- To fire the RemoteEvent.

When we activate a RemoteEvent with the FireServer() method, it automatically sends the player who activated it, then, now in the Script located in ServerScriptService.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(Player)
    -- Part Creation Code.
end)

I hope this has cleared up your doubts. If not, you can ask me :)

0
Thank you very much, I think it worked! I will test it with my friends right now and see if it works. InterDwarf 14 — 3y
0
:) genilsonotavio 132 — 3y
0
If it works, then you can mark it as answered, so you and him get points. R4nd0ml0l2 105 — 3y

Answer this question