Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

0

Thanks! Now I finally understand it! Your answer is helpful!

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.

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.

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)

1 comment

0

Thanks for your answer, but though I changed it it still does not work.

This discussion is preserved as it was. New answers, comments, and votes are closed.