#script not finding tool object even though its there

6 messages · Page 1 of 1 (latest)

silk hill
#

so i have this script where if the player activates the proximity prompt, it finds a tool in the character then prints the name of the tool (basically find the tool that the player is equipping)

ProximityPrompt.Triggered:Connect(function(player)

    local tool = player.Character:FindFirstChildOfClass("Tool")
    print(tool.Name)
    
end)

however, it doesnt print anything despite me equipping a tool. it also prints out this error

Workspace.WoodenPlaqueDisplayFrame.ProxPromptPart.Script:8: attempt to index nil with 'Name'

im seriously confused, did i do something wrong?

valid oasisBOT
#

studio** You are now Level 9! **studio

silk hill
#

i tried to check if its probably because the tool was given after the character spawned, so i tried it with one that you get when u spawn, and it worked. most likely it has to do something with how it was given to the player???

silk hill
#

OKAAY ignore this, turns out i just had to clone the tool using a script instead of a localscript. goddamnit

cold kelp
#

local proximityPrompt = script.Parent -- Replace "script.Parent" with the ProximityPrompt instance you want to use

proximityPrompt.Triggered:Connect(function(player)
local character = player.Character
if character then
local tool = character:FindFirstChildOfClass("Tool")
if tool then
print(tool.Name)
else
print("Player does not have a tool equipped")
end
else
print("Player character not found")
end
end)

#

try this