0
votes

I'm trying to send data from one LocalScript to another using a RemoteEvent through a script on the server side. First LocalScript is in StarterCharacterScripts, server-side Script is in workplace and the second LocalScript is under the player's character model.

I've set up print statements within each function to see where the communication is stopping, and it appears to be stopping when the server fires the function back at the second LocalScript. However, I can't determine the cause of this.

First LocalScript (StarterCharacterScripts)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
local UserInputService=game:GetService("UserInputService")
local player=game.Players.LocalPlayer
UserInputService.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode==Enum.KeyCode.G then
        createPartEvent:FireServer(251,226,11)
        print("Bing!")
    end
end)

Serverside Script (Workplace)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
createPartEvent.Name = "CreatePartEvent"
local fadePartEvent = Instance.new("RemoteEvent")
fadePartEvent.Parent=game.ReplicatedStorage
fadePartEvent.Name="FadePartEvent"

local function onCreatePartFired(player,red,green,blue)
    print("Ting!" ,player,red,green,blue)
    fadePartEvent:FireClient(player,red,green,blue)
end

createPartEvent.OnServerEvent:Connect(onCreatePartFired)

Second LocalScript (player model)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player=game.LocalPlayer
local fadePartEvent=ReplicatedStorage:WaitForChild("FadePartEvent")
fadePartEvent.Name="FadePartEvent"
local function onFadePartFired(player,red,green,blue)
    print("Done!")
        print(player,red,green,blue)
end

fadePartEvent.OnClientEvent:Connect(onFadePartFired)

If the code ran properly, the output should be:

Bing!
Ting! BusterTornado 251 226 11
Done! BusterTornado 251 226 11

However, the output shows as:

Bing! 
Ting! BusterTornado 251 226 11

Which would indicate that the function is not reaching the second LocalScript. I've tried searching around and I haven't found any answers as of yet.

1
You could have a race condition between the player's starter script firing and the character loading. One sanity check might be to add a print statement at the very end of the second localscript, just to verify that the event in ReplicatedStorage was properly located and the callback was in fact registered before the server fired its signal. - Kylaaa

1 Answers

0
votes

You simply use a BindableEvent, that can send data between [Server-side to Server-side] or [Client-side to Client-side]. Use :Fire on the localscript that sends the data and in the second localscript type .Event