so I'm trying to make a ButtonGui that when pressed will give a gun (clone) to the LocalPlayer but, the problem is that it cloned 2 times (i think) and ended up like this (2 of the same gun in the backpack) https://gyazo.com/23740e9dd6dec07ab059052eaefc4cd5
these are my scripts
01 | --server script |
02 | local famas = game.ReplicatedStorage.FAMAS |
03 | local scarL = game.ReplicatedStorage [ "SCAR-L" ] |
04 | local remote = Instance.new( "RemoteEvent" ) |
05 | remote.Parent = game.ReplicatedStorage |
06 | remote.Name = "WeaponEvent" |
07 | local active = game.StarterGui.Activated.Value |
08 | local playerName; |
09 | print ( "weaponscript test" ) |
10 |
11 | game.Players.PlayerAdded:Connect( function (player) |
12 | playerName = player.name |
13 | end ) |
14 | remote.OnServerEvent:Connect( function () |
15 | wait( 1 ) |
.
1 | --Local script |
2 |
3 | local button = script.Parent |
4 | local weaponRemote = game.ReplicatedStorage:WaitForChild( "WeaponEvent" ) |
5 |
6 | button.MouseButton 1 Click:Connect( function () |
7 | weaponRemote:FireServer() |
8 | end ) |
can anyone help?
You're not checking if they already have the tool or not. You should check that before doing anything.
01 | --server script |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local famas = ReplicatedStorage.FAMAS |
04 | local scarL = ReplicatedStorage [ "SCAR-L" ] |
05 | local remote = Instance.new( "RemoteEvent" ) |
06 | remote.Parent = ReplicatedStorage |
07 | remote.Name = "WeaponEvent" |
08 |
09 | -- # you don't need the PlayerAdded event listener here. |
10 | remote.OnServerEvent:Connect( function (client) |
11 | -- # client is the client that fired this remote event |
12 | if not client.Backpack:FindFirstChild( "FAMAS" ) and not client.Character:FindFirstChild( "FAMAS" ) then |
13 | famas:Clone().Parent = client.Backpack |
14 | end |
15 | end ) |
Notice the additional check made in the character. When a tool is equipped its parented out of the backpack into the character. So it's not in backpack if it's equipped.