Hi, so I’m making a gun that handles all visual effects on the client which, naturally, would require :FireAllClients()
But I noticed that if two people use it at the same time the :FireAllClients() will overlap and it won’t display correctly, as well as bool values being off because both are using that same remote event, any help?
Could you share the exact code? You might be able to tweak it in a certain way so it displays both effects simultaneously, maybe with a different table of information connected to different players.
This is the script that displays to all clients, I figured I wouldn’t show the functions because this should be enough to go off of.
local function shoot(plrWhoShot, tool, hitPos, target)
if ready then
local items = itemRetrieve.getItems(tool)
--
vfx(items, hitPos)
kill(target)
shootsfx(items)
switchClick(items, false)
ready = false
reload(items)
switchClick(items, true)
task.wait(.2)
ready = true
end
end
--
local function equipFunc(plr, tool)
local items = itemRetrieve.getItems(tool)
--
backMountTransparency(plr, 1)
task.wait(.75)
switchClick(items, false)
task.wait(.2)
ready = true
end
--
local function unequipFunc(plr, tool)
if ready then
local items = itemRetrieve.getItems(tool)
ready = false
switchClick(items, false, true)
task.wait(.5)
backMountTransparency(plr, 0)
tool.Parent = plr.Backpack
end
end
--
equipRemote.OnClientEvent:Connect(equipFunc)
unequip.OnClientEvent:Connect(unequipFunc)
fire.OnClientEvent:Connect(shoot)
This is really strange that the effects are merging, since variables are supposed to be different in different functions, but I guess that might be different since it’s a RemoteEvent. Could you maybe try storing all of the player’s bullet effect variables and stuff in a table that would sort of look like this?
local bullet_effects = {
["PlayerUsername"] = Effects -- With effects being a table with all the necessary values for each individual bullet
}
Well, it’s not really that. If two or more people equip it at once it breaks it for the other person since the “ready” variable gets changed. For example, if someone equipped the tool, and another person unequipped the tool, since the unequip function makes “ready” false
and checks if ready is true. Two people can’t unequip the tool once it’s equipped.
are you making a gun that is displaying ui?
what would need remote com (excluding verifying damage on the server)
No, it’s displaying parts moving on the gun
For example, a bolt on the gun, if they pull back the bolt, I need that to be seen by everyone
FireAllClients()
can only be fired on the server, which means that by default FireAllClients
will only be run once through the server. Calling FireAllClients()
multiple times isn’t inherently bad since you’d need to do this anyway for every client that shoots something and attempts to replicate it to other clients.
I don’t think you read the problem I’m having. But thank you for the info!
Would you mind showing us a visual demo? It might help to see what you mean.
I’m not really able to but, basically in the client script, you’ll see the ready
bool value gets changed to false, which doesn’t allow another player to unequip theirs since in order to unequip, it checks if ready
is true.
If someone could help, that’d be great!
I’m sorry, I’m not as experienced so I won’t risk leading you on the wrong path. Good luck with your problem.