attempt to index nil with 'Name' - Giving Tool?
Asked by
4 years ago Edited 4 years ago
Hello all,
I am trying to give a player a tool by clicking on him/her.
01 | local gui = script:WaitForChild( "ToolGiver" ) |
02 | local toolButton = script:WaitForChild( "Tool" ) |
03 | local groupId = 6301077 |
04 | local plr = game.Players.LocalPlayer |
05 | local mouse = plr:GetMouse() |
06 | local givingEvent = game.ReplicatedStorage:WaitForChild( "GivePlayerTools" ) |
08 | if plr:GetRankInGroup(groupId) > 240 then |
13 | mouse.Button 1 Down:Connect( function () |
14 | local target = mouse.Target |
15 | if mouse.target ~ = nil and target.Parent:FindFirstChild( "HumanoidRootPart" ) then |
16 | local givingPlayer = game.Players:GetPlayerFromCharacter(target.Parent) |
17 | local tools = plr.Backpack:GetChildren() |
18 | local currentGui = gui:Clone() |
19 | local givingTools = { } |
20 | local giveButton = currentGui:WaitForChild( "MainFrame" ):WaitForChild( "Give" ) |
21 | local replicatedFolder = Instance.new( "Folder" , game.ReplicatedStorage) |
23 | if plr.PlayerGui:FindFirstChild( "ToolGiver" ) then |
24 | plr.PlayerGui:FindFirstChild( "ToolGiver" ):Destroy() |
26 | currentGui.MainFrame.Player.Text = givingPlayer.Name |
27 | currentGui.Parent = plr.PlayerGui |
28 | for _, tool in pairs (tools) do |
29 | local currentButton = toolButton:Clone() |
30 | currentButton.Text = tool.Name |
31 | currentButton.Parent = currentGui.MainFrame.Tools |
32 | currentButton.MouseButton 1 Click:Connect( function () |
33 | if currentButton.BackgroundTransparency = = 0.3 then |
34 | table.remove(givingTools, tool) |
35 | currentButton.BackgroundTransparency = 0.8 |
37 | table.insert(givingTools, tool) |
38 | currentButton.BackgroundTransparency = 0.3 |
42 | giveButton.MouseButton 1 Click:Connect( function () |
44 | for _, tool in pairs (givingTools) do |
45 | tool.Parent = replicatedFolder |
47 | givingEvent:FireServer(replicatedFolder, givingPlr) |
LINE 26 IS RETURNING WITH "Players.kjduck.PlayerScripts.ToolGivingLocal:26: attempt to index nil with 'Name' "
Any help would be appreciated :D