What do you want to achieve? Keep it simple and clear!
I want to make a ProximityPrompt fire a signal to the player who triggered it
with a string. On the client, it should search for a ModuleScript under a Folder
to require (which returns a function that is activated).
What is the issue? Include screenshots / videos if possible!
The RemoteEvent is fired to the correct client, but sometimes, the client is not
detecting it. I know for sure that it’s firing but not detecting it because I have print
statements that execute on the server when fired, which always execute, as well as
print statements that execute as soon as a signal is received and print statements that execute after the function is connected. I check if the scripts
are enabled and loaded, and they always are.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried some things on the client like using :WaitForChild() with a timeout parameter (of 5 seconds) instead of FindFirstChild() to wait for the ModuleScript to load for a bit. If it’s nil after the 5 seconds, it will warn “ModuleScript is nil!”. Of course, these haven’t worked because the signal isn’t even received for some reason. Other than that, I haven’t tried much because I can’t possibly think of a cause for this. I have searched the developer forum (probably not hard enough) but have found nothing.
Here’s my scripts:
Server side that detects the triggering of the ButtonPrompt:
local l = false;
script.Parent.Head.ProximityPrompt.Triggered:Connect(function(p)
if not l then
l = true;
game.ReplicatedStorage.Bricks.Minigame:FireClient(p,"ticTacToe");
print("fired client ",p," with information of ticTacToe")
script.Parent.Head.ProximityPrompt:Destroy();
end;
end)
Client side that connects the function to the signal and requires the ModuleScript:
local v1 = require(script.Parent);
local f = script:WaitForChild("Minigames")
game.ReplicatedStorage.Bricks.Minigame.OnClientEvent:Connect(function(minigameType)
print("received")
local v2 = f:WaitForChild(minigameType,5)
if v2 then
print("true")
require(v2)(v1);
print("done performing function")
else
warn("ModuleScript is nil!")
end;
end)
print("connected")
Note that “v1” is a ModuleScript that is a part of a larger system.
Sooo… what’s going on, how come it’s not always detecting it?
local alreadyActivated = false;
script.Parent.Head.ProximityPrompt.Triggered:Connect(function(player)
if not alreadyActivated then
alreadyActivated = true;
game.ReplicatedStorage.Bricks.Minigame:FireClient(player,"ticTacToe");
print("fired client ",player," with information of ticTacToe")
script.Parent.Head.ProximityPrompt:Destroy();
end;
end)
And the client script:
local mainSystem = require(script.Parent);
local minigamesFolder = script:WaitForChild("Minigames")
game.ReplicatedStorage.Bricks.Minigame.OnClientEvent:Connect(function(minigameType)
print("received")
local potentialModuleScript = minigamesFolder :WaitForChild(minigameType,5)
if potentialModuleScript then
print("true")
require(potentialModuleScript)(mainSystem);
print("done performing function")
else
warn("ModuleScript is nil!")
end;
end)
print("connected")
Thank you so much! Okay, let’s figure this out - try adding a print statement outside of the if statement within the event’s’ :Connect() and see if it’s a problem with the proximity prompt itself.
Sorry for the late reply. After testing, every time I activated the ProximityPrompt, the print statement that happens under any conditions within the function was always activated, as well as the one that happens after the remote is fired. My code again:
local alreadyActivated = false;
script.Parent.Head.ProximityPrompt.Triggered:Connect(function(player)
print("triggered")
if not alreadyActivated then
alreadyActivated = true;
game.ReplicatedStorage.Bricks.Minigame:FireClient(player,"ticTacToe");
print("fired client ",player," with information of ticTacToe")
script.Parent.Head.ProximityPrompt:Destroy();
end;
end)
The client however, printed the “connected” text, showing that it was connected, but did not print “received”, “true”, “done performing function”, or warn “ModuleScript is nil!”, signing that it did not receive the signal. My client-side code again:
local mainSystem = require(script.Parent);
local minigamesFolder = script:WaitForChild("Minigames")
game.ReplicatedStorage.Bricks.Minigame.OnClientEvent:Connect(function(minigameType)
print("received")
local potentialModuleScript = minigamesFolder :WaitForChild(minigameType,5)
if potentialModuleScript then
print("true")
require(potentialModuleScript)(mainSystem);
print("done performing function")
else
warn("ModuleScript is nil!")
end;
end)
print("connected")
I’m not the greatest scripter and without going deep into your code: I had a similar error with an event sometimes not being detected on client side and I was absolutely clueless because the code looked actually good.
In the end the issue was something really stupid. I created the event as new instance at the beginning of my script but apparently I also created one already in ReplicatedStorage manually. As soon as I removed the duplicate event the client side started receiving perfectly. So my 2 cents here, check if the event exists twice or even multiple times by human error.