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

Remote Event Is not Firing on my Game?

Basically, The Idea of the game is, the first player to Press the Randomed Generated Key, wins the points, however, I must do it via LocalScript, so I must use Remote Events, but It's not working. What am I doing wrong

ServerScriptStorage

-- DEFINE CLICKDETECTORS
local ClickForRoomOne = workspace.RoomsToJoin.RoomOne.RoomOneClick
local remoteEvent = game.ReplicatedStorage.RemoteEvent
-- ROOM ONE
--DEFINE THE TABLE
local playersInRoomOne = {}

ClickForRoomOne.MouseClick:Connect(function(click)
	if #playersInRoomOne < 2 then
		-- PLAYER JOINS ROOMS
		
		--IF PLAYER IS ALREADY ON THE TABLE
			if table.find(playersInRoomOne, click) then
				print("You are already in the table!")
		else -- IF PLAYER IS NOT ON TABLE ALREADY
		table.insert(playersInRoomOne, click)
		
		local RoomOnePlayerOnePoints = 0
		local RoomOnePlayerTwoPoints = 0
		end 

		-- GAME STARTS -------------------------------
	if #playersInRoomOne == 2 then
		print("Game Starting")
		remoteEvent:FireServer()
	end
end)

StarterGUI (Local Script)


local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")

local ClickForRoomOne = workspace.RoomsToJoin.RoomOne.RoomOneClick
local playersInRoomOne = {}

ClickForRoomOne.MouseClick:Connect(function(click)
table.insert(playersInRoomOne, click)
end)

		local RoomOnePlayerOnePoints = 0
		local RoomOnePlayerTwoPoints = 0

list = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
local chosenKey = list[math.random(1, #list)]
print(chosenKey)

remoteEvent.OnServerEvent:Connect(function()
UserInputService.InputBegan:Connect(function(key)
    if [playersInRoomOne[1]]key.KeyCode == Enum.KeyCode[chosenKey] then
	RoomOnePlayerOnePoints = RoomOnePlayerOnePoints + 1
end
	 if [playersInRoomOne[2]]key.KeyCode == Enum.KeyCode[chosenKey] then
	local RoomOnePlayerTwoPoints = local RoomOnePlayerTwoPoints + 1
end
end)
end)

1 answer

Hello, EEnergy8. The problem is that you used RemoteEvent:FireServer() on a ServerScript and .OnServerEvent on a LocalScript. Instead, use RemoteEvent:FireClient(click) and .OnClientEvent. Try this:

Server/Regular Script:

- DEFINE CLICKDETECTORS
local ClickForRoomOne = workspace.RoomsToJoin.RoomOne.RoomOneClick
local remoteEvent = game.ReplicatedStorage.RemoteEvent
-- ROOM ONE
--DEFINE THE TABLE
local playersInRoomOne = {}

ClickForRoomOne.MouseClick:Connect(function(click)
    if #playersInRoomOne <= 2 then
        -- PLAYER JOINS ROOMS

        --IF PLAYER IS ALREADY ON THE TABLE
            if table.find(playersInRoomOne, click) then
                print("You are already in the table!")
        else -- IF PLAYER IS NOT ON TABLE ALREADY
        table.insert(playersInRoomOne, click)

        local RoomOnePlayerOnePoints = 0
        local RoomOnePlayerTwoPoints = 0
        end 

        -- GAME STARTS -------------------------------
    if #playersInRoomOne == 2 then
        print("Game Starting")
        remoteEvent:FireClient(click)
    end
end)

LocalScript:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")

local ClickForRoomOne = workspace.RoomsToJoin.RoomOne.RoomOneClick
local playersInRoomOne = {}

ClickForRoomOne.MouseClick:Connect(function(click)
table.insert(playersInRoomOne, click)
end)

        local RoomOnePlayerOnePoints = 0
        local RoomOnePlayerTwoPoints = 0

list = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
local chosenKey = list[math.random(1, #list)]
print(chosenKey)

remoteEvent.OnClientEvent:Connect(function()
UserInputService.InputBegan:Connect(function(key)
    if [playersInRoomOne[1]]key.KeyCode == Enum.KeyCode[chosenKey] then
    RoomOnePlayerOnePoints = RoomOnePlayerOnePoints + 1
end
     if [playersInRoomOne[2]]key.KeyCode == Enum.KeyCode[chosenKey] then
    local RoomOnePlayerTwoPoints = local RoomOnePlayerTwoPoints + 1
end
end)
end)

1 comment

0

It's still not working :( can you maybe add me discord so we can both fix this problem! Aft3rL1fe#8610

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