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

Player doesn't recieve item after being given?

ToolGivingSystem: (Script in ServerScriptService)

local groupId = 6301077
local ToolGive = Instance.new("RemoteEvent", game.ReplicatedStorage)
ToolGive.Name = "GivePlayerTools"

function giveTools(plr, toolFolder, givePlayer)
	print("Fired")
	if plr:GetRankInGroup(groupId) > -1 then
		print("Giving tools")
		local tools = toolFolder:GetChildren()
		for _, tool in pairs (tools) do
			tool.Parent = givePlayer.Backpack
			print("Given "..tool.Name)
		end
		toolFolder:Destroy()
	end
end

ToolGive.OnServerEvent:Connect(giveTools)

ToolGivingLocal: (LocalScript in StarterPlayerScripts)

local gui = script:WaitForChild("ToolGiver")
local toolButton = script:WaitForChild("Tool")
local groupId = 6301077
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")

if plr:GetRankInGroup(groupId) > 254 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)

1 comment

0

Are there any errors?

1 answer

For some reason, there's a problem when passing a player through a Remote Event, you should pass the player's Name property instead

Script:

local groupId = 6301077
local ToolGive = Instance.new("RemoteEvent", game.ReplicatedStorage)
ToolGive.Name = "GivePlayerTools"

function giveTools(plr, toolFolder, givePlayer)
    local player = game.Players[givePlayer]
    print("Fired")
    if plr:GetRankInGroup(groupId) > -1 then
        print("Giving tools")
        local tools = toolFolder:GetChildren()
        for _, tool in pairs (tools) do
            tool.Parent = player.Backpack
            print("Given "..tool.Name)
        end
        toolFolder:Destroy()
    end
end

ToolGive.OnServerEvent:Connect(giveTools)

Localscript:

local gui = script:WaitForChild("ToolGiver")
local toolButton = script:WaitForChild("Tool")
local groupId = 6301077
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")

if plr:GetRankInGroup(groupId) > 254 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.Name)
        end)
    end
end)

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