Problem when 2 users fire a remote event

I was testing my game today with another tester and I ran into a problem which occurred when 2 users fired a remote event to a server script, with that server script using a module script to use its code. Instead of both players getting a Particle Emitter like it was intended to do, it only effected 1 player?

Is this a Roblox issue or a issue with my use of module scripts?

Client:

script.Parent["Button"].MouseButton1Down:Connect(function()
	script.Parent.RemoteEvent:FireServer("Hola")
end)

Server:

script.Parent.OnServerEvent:Connect(function(p, Value)
	if Value == "Hola" then
		Module = require(game.ServerScriptService.Hola)
                Module:Test(p)
 	end
end)

Are the missing quotation marks from the client script a typo? If they are not, they’re probably not complete strings causing an error. Otherwise, everything seems fine

I did a typo in this post, it fires in the studio

First of all, the quotation marks, second of all, I wouldn’t recommend requiring the module right then and there last minute, and third of all, you’re saying “Module:Test(p)”, however, that isn’t the correct syntax for it. When declaring functions in a module, you access them like this:

examplemodule.Function(plr, args...)

I’m pretty sure what you’re saying is impossible, remoteevents don’t get mixed up. One player is one player and another player is another player, unless p in your script has been interfered with and has been improbably set to another player.

I think the p being sent to the module script is being set to another player when 2 players use it at the same time, like you said. How would I go about solving that problem?

can you send me the whole server script, please? An easy way would just be using another variable (identifier) that’s not already used.

Server:

script.Parent.OnServerEvent:Connect(function(p, Value)
	if debounce == false then
		debounce = true
		if Value == "Hola" then
			Module = require(game.ServerScriptService.Hola)
			Module:Test(p)
		end
	end
end)

Module:

local Aura = {}
function Aura:Test(p)
	c = p.Character
	for u, v in pairs(c.LowerTorso:GetDescendants()) do
		if v:IsA("ParticleEmitter") and v.Name == "Aura" then
			v:Destroy()
		end
		if v:IsA("Sound") and v.Name == "Burst" then
			v:Destroy()
		end
	end
	
	local New_Aura = game.ReplicatedStorage.Test:Clone()
	New_Aura.Name = "Aura"
	New_Aura.Parent = c
end
return Aura

Edit: This is incorrect, see following post.


You can only require a library once.

A detailed explanation can be found here.

Consider:

local m = require(path)

script.Parent.OnServerEvent:Connect(function(p, v)
    if v then
        m.func()
        -- code
    end
end)

Shouldn’t you be cloning it into the LowerTorso instead of the character model?

This is incorrect. You can require a library any number of times, modules just have caching behaviour, their contents are only run once on the first require, and then any subsequent require calls will return the same item that is returned from the initial call.

2 Likes

My fault - I misunderstood what I had read.

Maybe here’s the problem? If the debounce is placed on the server, then when two players fire the same function at the same time obiously only 1 player will get the particles. Just removing that debounce on the server should fix the problem

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.