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

Why is my Remote function not working when I trigger it?

Asked by 3 years ago

Hello, I'm implementing a code system to my game but when I trigger my RemoteFunction and access it in the server it does nothing

Here are the scripts

Local script (pressing a Gui button)

local button = script.Parent

button.MouseButton1Click:Connect(function()

    local event = game.ReplicatedStorage.CodeRemoteFunction
    local inputCode = script.Parent.Parent.TextBox.Text

    local result = event:InvokeServer(inputCode)

    if result == "Accepted" then
        inputCode = "Code succesfully redeemed!"
    else
        inputCode = "Code Invalid or already redeemed"
    end
end)

Server Script

local codesModule = require(game.ServerScriptService.CodesModule)

game.ReplicatedStorage.CodeRemoteFunction.OnServerInvoke = function(player, input)

    if codesModule[input] then
        codesModule[input](player)
        return "Accepted"
    else
        return "Rejected"
    end
end
0
Maybe try checking names of the RemoteEvents and other. robertruttar12 -115 — 3y
0
Check your module. SoftlockedUnderZero 668 — 3y
0
Put some prints in it, see where exactly it stops working. If there are any error those would help as well. Benbebop 1049 — 3y

1 answer

Log in to vote
-2
Answered by 3 years ago
Edited 3 years ago

I think you write wrong name or you named remote event wrong or you Or you just didn't added local to part of this script :

local codesModule = require(game.ServerScriptService.CodesModule)
------------------------------------------
game.ReplicatedStorage.CodeRemoteFunction.OnServerInvoke = function(player, input) 
------------------------------------------

    if codesModule[input] then
        codesModule[input](player)
        return "Accepted"
    else
        return "Rejected"
    end
end

The correct script is this :

local codesModule = require(game.ServerScriptService.CodesModule)

local game.ReplicatedStorage.CodeRemoteFunction.OnServerInvoke = function(player, input) 


    if codesModule[input] then
        codesModule[input](player)
        return "Accepted"
    else
        return "Rejected"
    end
end
0
No, this is worse. You're assigning OnServerInvoke to a function; the goal is to link OnServerInvoke to a function, not assign it. DeceptiveCaster 3761 — 3y
0
Ooh robertruttar12 -115 — 3y
Ad

Answer this question