Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Clicking on a tool giver gives more than 2 weapons?

So anyway I made two tool givers GUI, one gives a knife and pistol, the other a AWP and bloxy cola however clicking on one of those two tool giver GUI's will both give It to them, A example, If I clicked the GUI to give me the knife Instead of the pistol, It will give me the knife but also the gun as well, happens vise-versa

server script In ServerScriptService:

local Rep = game:GetService("ReplicatedStorage")
local event = Rep.RemoteEvent
local descendants = Rep.Weapons:GetDescendants()

local function giveTools(player)
	for index, descendant in pairs(descendants) do
		if descendant.Name == "Average knife" or descendant.Name == "Pistol" then
			local weaponsToGive = descendant:Clone()
			weaponsToGive.Parent = player.Backpack
		end
	end
end

event.OnServerEvent:Connect(giveTools)

local function giveTools(player)
	for index, descendant in pairs(descendants) do
		if descendant.Name == "AWP" or descendant.Name == "Bloxy Cola" then
			local weaponsToGive = descendant:Clone()
			weaponsToGive.Parent = player.Backpack
		end
	end
end

event.OnServerEvent:Connect(giveTools)

1 answer

If this is all in the same script, that would be because you are connecting the same event to two different functions (that have the same name) without any other parameters.

Try adding an argument to each function (the type of tools to give) and give the functions unique names.

local Rep = game:GetService("ReplicatedStorage")
local event = Rep.RemoteEvent
local descendants = Rep.Weapons:GetDescendants()

local function giveTools(player, toolsType)
    for index, descendant in pairs(descendants) do
		if toolsType == "KnifeAndPistol" then
			if descendant.Name == "Average knife" or descendant.Name == "Pistol" then
				local weaponsToGive = descendant:Clone()
				weaponsToGive.Parent = player.Backpack
			end
		elseif toolsType == "AWPAndCola" then
			if descendant.Name == "AWP" or descendant.Name == "Bloxy Cola" then
				local weaponsToGive = descendant:Clone()
				weaponsToGive.Parent = player.Backpack
			end
		end
    end
end

event.OnServerEvent:Connect(giveTools, toolsType)

Then in your local script, you can add the appropriate argument to the event.

For example:

event:FireServer("KnifeAndPistol") -- Will add the knife and pistol
event:FireServer("AWPAndCola") -- Will add the AWP and bloxy cola

6 comments

1

Its not working sorry

0

Are there any errors?

0

No, sorry If I responded late, It just won't appear In the backpack (StarterGear)

0

Also the local script:

1

Also the local script: local button = script.Parent local ScrollingFrame = script.Parent.Parent.Parent local Rep = game.ReplicatedStorage button.MouseButton1Click:Connect(function() ScrollingFrame.Visible = false Rep.RemoteEvent:FireServer(game.Players.LocalPlayer) end)

0

Ah I see the problem. Change line 21 to event.OnServerEvent:Connect(giveTools, player, toolsType)

This discussion is preserved as it was. New answers, comments, and votes are closed.