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

What is the error in these two script and local script?

Asked by 3 years ago

Hello, Thanks for your coming. What I am trying to do is a test for remote event, here is my script:

Script:

game.Players.PlayerAdded:Connect(function(player)
    Instance.new(“RemoteEvent”,game.ReplicatedStorage).Name = “message”
    Instance.new(“RemoteEvent”,game.ReplicatedStorage).Name = “answer”
    game.ReplicatedStorage.message:FireClient(player,“test”) --Mark 1 
    game.RpelicatedStorage.answer.OnServerEvent:Connect(function(data)
        print(data)
    end)
end)

Local Script:

game.ReplicatedStorage.message.OnClientEvent:Connect(function(data)
    game.ReplicatedStorage.answer:FireServer(data)
end)

from my exception and inference, the output should be what I put after player at mark 1, but actually it does nothing at all, so what is the error? If you know then please answer me. Thanks!

2 answers

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

Client is not yet loaded, PlayerAdded fires when you enter the game which is long time before your local scripts actually run, that way when on line 4 you fire the event, your local script is not receiving it as it yet did not run so it did not connect the function, i have answered same answer here.

0
Thanks! Now I finally understand it! Your answer is helpful! willywillycow 50 — 3y
0
Hi, I tried add a new remote event called added and used the same method as what you said in the last post, but it still does not work. willywillycow 50 — 3y
0
May i ask i see you are creating 2 remote events on line 2 and 3, you create them and then instantly fire them, are you sure your client has referenced the remote events right? Did you do from the local script: ReplicatedStorage:WaitForChild('message')? Or why don't you just make tthe event in studio? Also make sure to fix what CjayPlyz say, his answer is correct there. imKirda 4491 — 3y
Ad
Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
3 years ago
Edited 3 years ago

From what I can see, your problems are:

1.The parameters of OnServerEvent is player and arguments or the data passed through the FireServer()

2.You spelled your ReplicatedServer wrong.

So use this instead:

game.ReplicatedStorage.answer.OnServerEvent:Connect(function(player, data)
    print(data)
end)
0
Thanks for your answer, but though I changed it it still does not work. willywillycow 50 — 3y

Answer this question