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

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

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

3 comments

0

Maybe try checking names of the RemoteEvents and other.

0

Check your module.

0

Put some prints in it, see where exactly it stops working. If there are any error those would help as well.

1 answer

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

2 comments

0

No, this is worse. You're assigning OnServerInvoke to a function; the goal is to link OnServerInvoke to a function, not assign it.

0

Ooh

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