FireClient -> OnServerEvent -- Not take Data from RemoteEvent

I have 4 Scripts in ServerScriptService with name ScriptLeverA,B,C and D
To send the date over FireClient have code

local RS = game:GetService("ReplicatedStorage")
local leverEventA = RS.LeverEventA
--code
--code
local function onTriggeredA(player)
    if isCframe1 then
        isCframe1 = false
        isCframe2 = true		
        tweenMovingPartToA(cframe2)
		stateA = true
    elseif isCframe2 then
        isCframe1 = true
        isCframe2 = false
        tweenMovingPartToA(cframe1)
		stateA = false
    end

	print("stateA = OnTriggeredA ----", stateA)
    -- odesílá informaci o hráči
    leverEventA:FireClient(player, stateA)

in video I use control print “stateA = OnTriggeredA ----”, variable
Its ready

As if Not RemoteEvent LeverEventA

local RS = game:GetService("ReplicatedStorage")
local leverEventA = RS.LeverEventA
--code
--code
leverEventA.OnServerEvent:Connect(function(player, stateA)
print("Lever A was press player -- :", player, stateA)

video example:

Explorer:

If you are ideas why not sending me RemoteEvent Data
Thanks
Codycheck

Because you are firing it to the client, you are not using leverEventA:FireServer()

Error
FireServer can only be called from the client - Server - ScriptLeverA:70

Is the second script a local script?

We need to figure out which is a local script and which is a server script

If the second script is a local script, then it would be this:
leverEventA.OnClientEvent:Connect(function(player, stateA)
print(“Lever A was press player – :”, player.Name, stateA)

And if the first script is a server script, then it’d be fireclient the same way you had it before.

Nevermind I misunderstood mb.
From which local script are you calling the second script? Since server scripts can’t call :FireServer()

Both (actually 5 scripts ) is ServerScript (ScriptSeverA,B,C and D, and ServerScript)

FireServer it was Testing
Roblox will allow me just FireClient

Cody

then a local script needs to have OnClientEvent to grab the data.

Its OK, I’m sitting at that morning, And I no longer have energy to solve myself :slight_smile:

Script into ServerScriptService

print("LEVER A")

-- Services --
local TweenService = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
-- Instances --
local ProximityPromptsA = game.Workspace.TREZORDVEREA.Levers.PackaA.LeverA["Proximity Prompts"]
local leverEventA = RS.LeverEventA
local kombinaceRemoteEventA = RS.KombinaceEvent
-- Variables --
local proximityPromptsA = {}
local connections = {}
local Settings = script.Settings
local movingPart = Settings["Moving part"].Value
local part1 = Settings["Position 1"].Value
local part2 = Settings["Position 2"].Value
local cframe1 = part1.CFrame
local cframe2 = part2.CFrame
local tweenDuration = Settings["Time"].Value
local removePositionParts = Settings["Remove position parts"].Value
local Advanced = Settings.Advanced
local easingStyle = Advanced.EasingStyle.Value
local easingDirection = Advanced.EasingDirection.Value
local isCframe1 = true ---- Výchozí pozice
local isCframe2 = false
local tween
local stateA = false
-- Functions --
local function setupA()
    movingPart.CFrame = cframe1
    if removePositionParts then
        part1:Destroy()
        part2:Destroy()
    end
end
local function getProximityPromptsA()
    for index, child in pairs(ProximityPromptsA:GetChildren()) do
        if child:IsA("ObjectValue") then
            local prompt = child.Value
            if prompt:IsA("ProximityPrompt") then
                table.insert(proximityPromptsA, prompt)
            end
        end
    end
end
local function tweenMovingPartToA(cframe)
    if tween then
        tween:Cancel()
        tween:Destroy()
    end
    local tweenInfo = TweenInfo.new(tweenDuration, easingStyle, easingDirection)
    tween = TweenService:Create(movingPart, tweenInfo, {CFrame = cframe})
    tween:Play()
end
local function onTriggeredA(player)
    if isCframe1 then
        isCframe1 = false
        isCframe2 = true		
        tweenMovingPartToA(cframe2)
		stateA = true
    elseif isCframe2 then
        isCframe1 = true
        isCframe2 = false
        tweenMovingPartToA(cframe1)
		stateA = false
    end

	print("stateA = OnTriggeredA ----", stateA)
    -- odesílá informaci o hráči
    leverEventA:FireClient(player, stateA)
   
    -- Odeslání stavu levérů a informací o kombinaci na server pomocí RemoteEvent
    kombinaceRemoteEventA:FireClient(player, stateA)
end
-- Code --
setupA()
getProximityPromptsA()
for index, prompt in ipairs(proximityPromptsA) do
    local connection = prompt.Triggered:Connect(onTriggeredA)
    table.insert(connections, connection)
end

ServerScript TREZOR too into ServerScriptService

print("TREZOR")

-- Služby --
local RS = game:GetService("ReplicatedStorage")
local Kombinace = require(RS.Modules.Kombinace)
local ButtonEnter = game.Workspace.TREZORDVEREA.Levers.PodlozkaEnter.ProximityPrompt
print("Je to ButtonEnter", ButtonEnter)

-- RemoteEvents pro jednotlivé levéry
local leverEventA = RS.LeverEventA
local leverEventB = RS.LeverEventB
local leverEventC = RS.LeverEventC
local leverEventD = RS.LeverEventD

local doopen = game.Workspace.Sound.dooropen
local doclose = game.Workspace.Sound.doorclose

local trezordvereA = game.Workspace.TREZORDVEREA
local dverevpravo = trezordvereA.DvereVpravo
local dverevlevo = trezordvereA.DvereVlevo
local RSettings = dverevpravo.RSettings
local LSettings = dverevlevo.LSettings

local RmovingPart = RSettings["R Moving part"].Value
local Rpart1 = RSettings["R Position 1"].Value
local Rcframe1 = Rpart1.CFrame
local Rpart2 = RSettings["R Position 2"].Value
local Rcframe2 = Rpart2.CFrame

local LmovingPart = LSettings["L Moving part"].Value
local Lpart1 = LSettings["L Position 1"].Value
local Lcframe1 = Lpart1.CFrame
local Lpart2 = LSettings["L Position 2"].Value
local Lcframe2 = Lpart2.CFrame

local RAdvanced = RSettings.RAdvanced
local ReasingStyle = RAdvanced.REasingStyle.Value
local ReasingDirection = RAdvanced.REasingDirection.Value
local RTime = RSettings["R Time"].Value

local LAdvanced = LSettings.LAdvanced
local LeasingStyle = LAdvanced.LEasingDirection.Value
local LeasingDirection = LAdvanced.LEasingStyle.Value
local LTime = LSettings["L Time"].Value

local GENERATION_INTERVAL = 120

local Rmoving = dverevpravo.RMovingPart
local Rposition1 = dverevpravo.RPosition1
local Rposition2 = dverevpravo.RPosition2

local Lmoving = dverevlevo.LMovingPart
local Lposition1 = dverevlevo.LPosition1
local Lposition2 = dverevlevo.LPosition2

local currentCombination = Kombinace.currentCombination

-- Funkce pro otevření pravých a levých dveří --
local function openRightDoor()
    print("Otevírám pravé dveře")
    local tweenInfo = TweenInfo.new(RTime, ReasingStyle, ReasingDirection)
    local tween = game:GetService("TweenService"):Create(RmovingPart, tweenInfo, {CFrame = Rcframe2})
    tween:Play()
end

local function openLeftDoor()
    print("Otevírám levé dveře")
    local tweenInfo = TweenInfo.new(LTime, LeasingStyle, LeasingDirection)
    local tween = game:GetService("TweenService"):Create(LmovingPart, tweenInfo, {CFrame = Lcframe2})
    tween:Play()
end




-- Funkce pro ověření kombinace --
function checkCombination(stateA, stateB, stateC, stateD)
    print("Aktuální kombinace - checkCombination:", currentCombination) -- Kontrolní výpis aktuální kombinace

		print("Obsah kombinace:")
		local kombinace = currentCombination
		for i, value in ipairs(kombinace) do
		    print("Pozice", i, "=", value)
		end
		
				-- Naslouchání událostem od jednotlivých levérů a spouštění ověření kombinace
		leverEventA.OnServerEvent:Connect(function(player, stateA)
		    print("Lever A byl zmáčknut hráčem:", player, stateA)
		    checkCombination(stateA, Kombinace.currentCombination[2], Kombinace.currentCombination[3], Kombinace.currentCombination[4])
		end)

		leverEventB.OnServerEvent:Connect(function(player, stateB)
		    print("Lever B byl zmáčknut hráčem:", player.Name)
		    checkCombination(Kombinace.currentCombination[1], stateB, Kombinace.currentCombination[3], Kombinace.currentCombination[4])
		end)

		leverEventC.OnServerEvent:Connect(function(player, stateC)
		    print("Lever C byl zmáčknut hráčem:", player.Name)
		    checkCombination(Kombinace.currentCombination[1], Kombinace.currentCombination[2], stateC, Kombinace.currentCombination[4])
		end)

		leverEventD.OnServerEvent:Connect(function(player, stateD)
		    print("Lever D byl zmáčknut hráčem:", player.Name)
		    checkCombination(Kombinace.currentCombination[1], Kombinace.currentCombination[2], Kombinace.currentCombination[3], stateD)
		end)

    	-- Ověření, zda aktuální kombinace odpovídá nastavení pák
    	local combination = Kombinace[currentCombination]
		if combination[1] == stateA and
		   combination[2] == stateB and
		   combination[3] == stateC and
		   combination[4] == stateD then
        -- Správná kombinace, otevřít dveře
        print("Správná kombinace! Otevírám dveře.")
        doopen:Play() -- Přehrání zvuku otevření dveří
        openRightDoor() -- Otevření pravých dveří
        openLeftDoor() -- Otevření levých dveří
        
        -- Resetování kombinace po časovém intervalu
        wait(GENERATION_INTERVAL)
        currentCombination = nil
    else
        -- Nesprávná kombinace, zůstávají uzamčeny
        print("Nesprávná kombinace! Dveře zůstávají uzamčeny.")
    end
end



-- Obsluha události ProximityPrompt
ButtonEnter.Triggered:Connect(function()
    print("ProximityPrompt aktivován. Odesílám kombinaci z LEVERů.")

    -- Funkce pro výpis obslužných funkcí pro levéry
    local function printLeverEvents()
        print("Přidávám obslužné funkce pro levéry:")
        leverEventA.OnServerEvent:Connect(function(player, stateA)
            print("Lever A byl zmáčknut hráčem:", player, stateA)
        end)
        leverEventB.OnServerEvent:Connect(function(player, stateB)
            print("Lever B byl zmáčknut hráčem:", player, stateB)
        end)
        leverEventC.OnServerEvent:Connect(function(player, stateC)
            print("Lever C byl zmáčknut hráčem:", player, stateC)
        end)
        leverEventD.OnServerEvent:Connect(function(player, stateD)
            print("Lever D byl zmáčknut hráčem:", player, stateD)
        end)
    end

    -- Přidání obslužných funkcí pro levéry a zároveň spuštění kontroly kombinace
    if currentCombination then
        printLeverEvents() -- Výpis obslužných funkcí pro levéry
        checkCombination(Kombinace.currentCombination[1], Kombinace.currentCombination[2], Kombinace.currentCombination[3], Kombinace.currentCombination[4]) -- Kontrola kombinace
    else
        print("Chyba: Počáteční kombinace nebyla vygenerována.")
    end
end)
print("Používáme pevně danou kombinaci:", currentCombination)

Second Script “But there’s a nice mess in that”
“RemoteEvent” Because he still doesn’t send me data
FALSE AND TRUE

Codycheck

and ModuleScript

-- Komunikace ModuleScript
print("KOMBINACE SCRIPT")

local Kombinace = {} -- Tato tabulka bude obsahovat funkcionalitu pro manipulaci s kombinacemi
Kombinace.currentCombination = "kombinace2"  -- nebo jakákoliv jiná výchozí hodnota

local kombinaceData = {
    kombinace1 = {false, true, false, false},
    kombinace2 = {true, false, true, false},
    kombinace3 = {true, true, false, true},    
}
Kombinace.currentCombination = kombinaceData.kombinace2 -- Nastavení výchozí kombinace

return Kombinace -- Vrátit modul

I see that your initial error occurs at line 109 in TREZOR, which is if combination[1] == stateA. The error suggests that the combination table is nil (you tried to index nil with the number 1). Therefore, the line where you define this (local combination = Kombinace[currentCombination]) returns nil.
The problem isn’t that the data isn’t being sent over, the problem is that currentCombination doesn’t exist in Kombinace.
currentCombination is defined as Kombinace.currentCombination, and that is defined as kombinaceData.kombinace2. The problem here is that you’re trying to index the module Kombinace (which already is wrong) with the values, rather than the key. What I think you were trying to do is index the table kombinaceData in the module with the key/name of the current combination.
The solution is to remove local combination = Kombinace[currentCombination] and change the if statement at line 109 to:

if currentCombination[1] == stateA and
   currentCombination[2] == stateB and
   currentCombination[3] == stateC and
   currentCombination[4] == stateD then

because currentCombination is the table with the correct combinations.

1 Like

Thanks *TestyLike3
I have already come to the door which is a joyful news.
Thank You
video example:


CZ-in video
20:43:31.190 Správná kombinace! Otevírám dveře. - Server - TREZOR:114
20:43:31.190 Otevírám pravé dveře - Server - TREZOR:60
20:43:31.190 Otevírám levé dveře - Server - TREZOR:67
ENG
20: 43: 31.190 The right combination! I open the door. - server - safe: 114
20: 43: 31.190 I open the right door - server - safe: 60
20: 43: 31.190 I open the left door - server - safe: 67

PS: That they don’t open them will be some stupidity, maybe Anchored, etc

Thanks
Codycheck

So all the wrong
Because, I got tangled in that
I have 2x CheckCombination

function checkCombination(stateA, stateB, stateC, stateD)

and

checkCombination(Kombinace.currentCombination[1], Kombinace.currentCombination[2], Kombinace.currentCombination[3], Kombinace.currentCombination[4]) -- Kontrola kombinace

currentCombination are data from modulescipt

Just RemoteEvent coughs on me :slight_smile:

Old variant ModuleScript “Kombinace” with numbers “0 – down” and “1 – up”
It also didn’t work, because RemoteEvent dont send DATA

print("KOMBINACE SCRIPT")

local Kombinace = {}

-- Pevně daná kombinace
Kombinace.currentCombination = "kombinace2"

local kombinaceData = {
    kombinace1 = {0, 1, 0, 0},
    kombinace2 = {1, 0, 1, 0},
    kombinace3 = {1, 1, 0, 0},
    kombinace3 = {0, 1, 0, 1},
    kombinace4 = {1, 1, 1, 0},
	Kombinace5 = {0, 0, 1, 1},
	Kombinace6 = {1, 1, 0, 0},
	Kombinace7 = {0, 1, 1, 0},
	Kombinace8 = {1, 0, 0, 1},
	Kombinace9 = {1, 0, 0, 0},
	Kombinace10 = {0, 0, 1, 0},
	Kombinace11 = {1, 1, 1, 1},
	Kombinace12 = {0, 1, 1, 1},
	Kombinace13 = {0, 0, 0, 1},
	Kombinace14 = {1, 0, 1, 1},
	
}

local currentPositions = {0, 0, 0, 0}

function Kombinace:setPosition(lever, position)
    if lever == "A" then
        currentPositions[1] = position == "Position1" and 0 or 1
    elseif lever == "B" then
        currentPositions[2] = position == "Position1" and 0 or 1
    elseif lever == "C" then
        currentPositions[3] = position == "Position1" and 0 or 1
    elseif lever == "D" then
        currentPositions[4] = position == "Position1" and 0 or 1
    end
end




function Kombinace:checkCombination(positionA, positionB, positionC, positionD)
		if typeof(positionA) == "Instance" then
	    	print("positionA je instance.")
		else
	    	print("positionA není instance.")
		end

		if typeof(positionB) == "Instance" then
	    	print("positionB je instance.")
		else
	    	print("positionB není instance.")
		end

		if typeof(positionC) == "Instance" then
	    	print("positionC je instance.")
		else
	    	print("positionC není instance.")
		end
		
		if typeof(positionD) == "Instance" then
	    	print("positionD je instance.")
		else
	    	print("positionD není instance.")
		end

    local combinationName = "kombinace" .. positionA .. positionB .. positionC .. positionD
    local combination = kombinaceData[combinationName]
    print("COMBINATION", combination)
			print("Obsah kombinace2:")
			local kombinace2 = kombinaceData.kombinace2
			for i, value in ipairs(kombinace2) do
    print("Pozice", i, "=", value)
end
    if combination then
        for i = 1, 4 do
            print("Aktuální kombinace:", combination[i])
            if combination[i] ~= currentPositions[i] then
                return false
            end
        end
        return true
    else
        error("Neplatná kombinace!")
    end
end

print("Obsah kombinace2:")
local kombinace2 = kombinaceData.kombinace2
for i, value in ipairs(kombinace2) do
    print("Pozice", i, "=", value)
end

-- Přidejme pevně danou kombinaci k objektu Kombinace
Kombinace.currentCombination = kombinace2

print("KOMBINACE DATA", Kombinace, kombinaceData)

return Kombinace

Cody

It appears that the value of LeasingDirection doesn’t match the enum Enum.EasingDirection that TweenInfo is looking for. Can you print the value of LeasingDirection before line 68?

now I look code :slight_smile:

local LeasingStyle = LAdvanced.LEasingDirection.Value
local LeasingDirection = LAdvanced.LEasingStyle.Value

Cody

OnServerEvent doesn’t have a player argument, remove that, and just have stateA.