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

attempt to index nil with 'Name' - Giving Tool?

Asked by
kjduck 0
4 years ago
Edited 4 years ago

Hello all,

I am trying to give a player a tool by clicking on him/her.

01local gui = script:WaitForChild("ToolGiver")
02local toolButton = script:WaitForChild("Tool")
03local groupId = 6301077
04local plr = game.Players.LocalPlayer
05local mouse = plr:GetMouse()
06local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")
07 
08if plr:GetRankInGroup(groupId) > 240 then
09    wait(1)
10    script:Destroy()
11end
12 
13mouse.Button1Down:Connect(function()
14    local target = mouse.Target
15    if mouse.target ~= nil and target.Parent:FindFirstChild("HumanoidRootPart") then
View all 50 lines...

LINE 26 IS RETURNING WITH "Players.kjduck.PlayerScripts.ToolGivingLocal:26: attempt to index nil with 'Name' "

Any help would be appreciated :D

0
Can you put the script on the website i rather not click or download files IcyMizu 122 — 4y
0
Is this a Script or a LocalScript? cucucu0001 35 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You didn't check if the mouse.Hit was a player or not. Updated Code:

01local gui = script:WaitForChild("ToolGiver")
02local toolButton = script:WaitForChild("Tool")
03local groupId = 6301077
04local plr = game.Players.LocalPlayer
05local mouse = plr:GetMouse()
06local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")
07 
08if plr:GetRankInGroup(groupId) > 240 then
09  wait(1)
10  script:Destroy()
11end
12 
13mouse.Button1Down:Connect(function()
14local target = mouse.Target
15if mouse.target ~= nil and target.Parent:FindFirstChild("HumanoidRootPart") then
View all 51 lines...
Ad

Answer this question