Ad
Log in to vote
0

Clicking on a tool giver gives more than 2 weapons?

Asked by 14 days ago

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

Log in to vote
1
Answered by 14 days ago

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
1
Its not working sorry imnotaguest1121 74 — 14d
0
Are there any errors? namespace25 594 — 14d
0
No, sorry If I responded late, It just won't appear In the backpack (StarterGear) imnotaguest1121 74 — 14d
0
Also the local script: imnotaguest1121 74 — 14d
View all comments (2 more)
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) imnotaguest1121 74 — 14d
0
Ah I see the problem. Change line 21 to event.OnServerEvent:Connect(giveTools, player, toolsType) namespace25 594 — 13d
Ad

Answer this question