My Button gives multiple weapons but I want It to give only one How can I fix this?

  1. What do you want to achieve? A button that gives ONE weapon

  2. What is the issue? Button gives multiple weapons.

  3. What solutions have you tried so far? Editing the code and looking on the Dev Forum

My code that gives one weapon:
local Event = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)

local Tool = game.ServerStorage:WaitForChild(“BeginnerWand”)

Event.OnServerEvent:Connect(function(Player)

local ToolClone = Tool:Clone()

ToolClone.Parent = Player.Backpack

local ToolClone = Tool:Clone()

ToolClone.Parent = Player.StarterGear

end)

My code that gives the other Weapon:

local Event = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)

local Tool = game.ServerStorage:WaitForChild(“Bow”)

Event.OnServerEvent:Connect(function(Player)

local ToolClone = Tool:Clone()

ToolClone.Parent = Player.Backpack

local ToolClone = Tool:Clone()

ToolClone.Parent = Player.StarterGear

end)

This code is in the starterGui for both weapons:

local RemoteEvent = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)

local Button = script.Parent

Button.MouseButton1Down:Connect(function()

RemoteEvent:FireServer()

Button.Parent.Visible = false

end)

Please leave feedback Thank you for reading this and if you helped also thank you!!!

use code blocks

so I am changing my reply because I noticed I was wrong

the reason you get multiple weapons is because you have two events firing at once

1 Like

Yeah I was just about to reply saying it was wrong. So what do I do?

yea I forgot parenting things to StarterGui only changes after you respawn, basically how StarterGui works

:joy:

@D0RYU So do you have any suggestions on how to fix this?

well why do you have two OnServerEvent’s anyways?

I had a button that worked so I just copied the code over.

:slightly_frowning_face:

well basically if you call :FireServer(), then every OnServerEvent will run
so that is why you would get more then 1 tool

if you want you could add a parameter which would say which tool you want to clone, as only have one OnServerEvent

EXAMPLE:
local script

local RemoteEvent = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)
local Button = script.Parent

Button.MouseButton1Down:Connect(function()
    RemoteEvent:FireServer("Bow")
    Button.Parent.Visible = false
end)

server script

local Event = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)

Event.OnServerEvent:Connect(function(Player, ToolName)
    local Tool = game.ServerStorage:WaitForChild(ToolName)
    local ToolClone1 = Tool:Clone()
    local ToolClone2 = Tool:Clone()

    ToolClone1.Parent = Player.Backpack
    ToolClone2.Parent = Player.StarterGear
end)

as you can see I put in “Bow” for the :FireServer(), you would change that to the tool you want

1 Like

Where would I put the code? In the serverscriptstorage?

that first script is for that part

the second script is for this part

You don’t need tool number 2 to be cloned or even need it at all. But thanks! @D0RYU why am I getting 2 of the same tool? If you could fix this I would mark it as solved.

well I was just doing what your code did in a way I would do it,

why can’t you just parent a clone to the Backpack and make a tool save script in ServerScriptService?

I dont understand the second part should I just add a script to delete the second tool @D0RYU?

Maybe that’s just because you firing 2 objects to 1 remote event. Try to add another remote event then edit the script.

@AmitRoblox1987 Where would I add the remote event? and how should I edit the script? (I am a noob at coding)

First of all, What other item you wanna add?

None the only item I want is either the bow or wand. In other words only ONE tool.

I gtg soon @AmitRoblox1987 Leave the solution below Ill ping you later by using your name when I am back online and thank you for helping.

Wait a second, In line 7, you just added tool in startergear which means, StarterGear will add item auto. For more information:
StarterGear | Roblox Creator Documentation.

So in final remove line 7. Because you already used to give item
to player backpack.

Thats my old code and I rlly gotta run Here is my new code:

local Event = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)

Event.OnServerEvent:Connect(function(Player, ToolName)
local Tool = game.ServerStorage:WaitForChild(ToolName)
local ToolClone1 = Tool:Clone()

ToolClone1.Parent = Player.Backpack

end)

and:

local RemoteEvent = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)

local Button = script.Parent

Button.MouseButton1Down:Connect(function()

RemoteEvent:FireServer(“BeginnerWand”)

Button.Parent.Visible = false

end)