Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this code send the item to the player's Backpack?

Asked by 6 years ago
local gui = script:WaitForChild("ToolGiver")
local toolButton = script:WaitForChild("Tool")
local groupId = 2921053
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")

if plr:GetRankInGroup(groupId) < 0 then 
    wait(1)
    script:Destroy()
end

mouse.Button1Down:Connect(function()
    local target = mouse.Target
    if mouse.target ~= nil and target.Parent:FindFirstChild("HumanoidRootPart") then
        local givingPlr = game.Players:GetPlayerFromCharacter(target.Parent)
        local tools = plr.Backpack:GetChildren()
        local currentGui = gui:Clone()
        local givingTools = {}
        local giveButton = currentGui:WaitForChild("MainFrame"):WaitForChild("Give")
        local replicatedFolder = Instance.new("Folder", game.ReplicatedStorage)

        if plr.PlayerGui:FindFirstChild("ToolGiver") then
            plr.PlayerGui:FindFirstChild("ToolGiver"):Destroy()
        end
        currentGui.MainFrame.Player.Text = givingPlr.Name
        currentGui.Parent = plr.PlayerGui
        for _, tool in pairs (tools) do
            local currentButton = toolButton:Clone()
            currentButton.Text = tool.Name
            currentButton.Parent = currentGui.MainFrame.Tools
            currentButton.MouseButton1Click:Connect(function()
                if currentButton.BackgroundTransparency == 0.3 then
                    table.remove(givingTools, tool)
                    currentButton.BackgroundTransparency = 0.8
                else
                    table.insert(givingTools, tool)
                    currentButton.BackgroundTransparency = 0.3
                end
            end)
        end
        giveButton.MouseButton1Click:Connect(function()
            currentGui:Destroy()
            for _, tool in pairs (givingTools) do
                tool.Parent = replicatedFolder
            end
            givingEvent:FireServer(replicatedFolder, givingPlr)
        end)
    end
end)

When I press the Give button, it destroys the item, instead of giving it to the other player.``

0
Correct me if I'm wrong, but it looks like you're deleting the GUI before it can initiate the givingEvent on line 43 IrishStukov 20 — 6y

Answer this question