Hey Roblox devs. I was testing out my game with 2 players, and when you selected a weapon it duplicates that weapon into your inventory to the amount of players in the game. For example, if there were 4 players in the game and you selected a weapon, you would have 4 duplicates of that weapon in your inventory.
I have a gun selecting menu, and when you select a gun it clones it from replicated storage into your inventory. I have remote events for when you select a weapon. The gun gets cloned into the player inventory through a server script, and it detects when a player selects the gun in a local script.
Here is the local script:
selectButton.MouseButton1Down:Connect(function()
print("select local")
selectButton.MouseButton1Up:Connect(function()
selectButton.Visible = false
selectButton.Active = false
DiscardButton.Visible = true
DiscardButton.Active = true
end)
GunEquip:FireServer(ARselected)
globalGunSelected = "Blackout"
end)
Here is the server script:
local GunEquip = game.ReplicatedStorage.gunEvents.GunEquip
local Blackout = game.ReplicatedStorage.guns.Blackout
GunEquip.OnServerEvent:Connect(function(player, ARselected)
if ARselected == ".300 AAC Blackout" then
local BlackoutClone = Blackout:Clone()
BlackoutClone.Parent = player.Backpack
end
end)
Blackout represents the gun name, don’t worry about that, and don’t worry about “discard button” either.
duplicates that weapon into your inventory to the amount of players in the game. For example, if there were 4 players in the game and you selected a weapon, you would have 4 duplicates of that weapon in your inventory.
If i get this right. You want the server to give all num players in that game said weapon but only 1 and no more??
If ONE player selects a gun, only THAT player gets the gun. That’s how I have it right now, but when there’s say 4 players and ONE player selects a gun for only themselves, it gives them 4 guns. I want it to only give 1 gun.
The server event runs for every player in the game. Instead of having the remote event in RP, have it be inside somewhere only the client would search. For example, inside the character or something. So every single player has their own remote event
OR
Check if the server is receiving the correct player
game.ReplicatedStorage.RemoteEvent:FireServer(Player)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Client)
if Player == Client then
--iuwenf
end
end)
I know the server is recieving the right player, I’ve tested it out already.
Would it work if I put the remote event inside the tool itself?
It recieves the player because the server script has the correct player already, but it fires multiple times because the server script fires for every player in the game. The way I just told you would fix that.
Yeah, it would work inside the tool if only one person called out for that event
If I have a remote event in a player, how can I access that through the server? Since I have to identify the remote event first in order to be able to detect it, like this:
local remoteEvent = --?
remoteEvent.OnServerEvent:Connect(function()
--code
end