What do you want to achieve? Keep it simple and clear!
I want my bandage tool to make it so it drops a bandage down for anyone to pick up and heal themselves.
What is the issue? Include screenshots / videos if possible!
there is an error where it says “attempt to index nil with ‘FindFirstChild’”. But the thing is I replaced all of my variables with “WaitForChild” and it still doesn’t work. I have looked at the dev forum too.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked at other people’s posts about this problem. But none of them was my solution
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Tool = script.Parent.Parent
local Configurations = Tool:FindFirstChild("Configurations")
local AmountOfbandages = Configurations:WaitForChild("AmountOfBandages").Value
local HealAmount = Configurations:FindFirstChild("HealAmount").Value
local Cooldown = Configurations:FindFirstChild("Cooldown").Value
local CanDrop = true
Tool.Activated:Connect(function()
if CanDrop and AmountOfbandages > 0 then
local ModelClone = Tool:FindFirstChild("Handle"):Clone()
ModelClone.Parent = game.Workspace
ModelClone.Position = Tool.Handle.Position
ModelClone.CanCollide = true
CanDrop = false
AmountOfbandages = AmountOfbandages - 1
print(AmountOfbandages)
ModelClone.Touched:Connect(function(hit)
local Humanoid = hit.Parent.Parent:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
ModelClone.Use.Playing = true
Humanoid.Health = Humanoid.Health + HealAmount
end
end)
for i = Cooldown + 1,0,-1 do
wait(1)
if i == 1 then
CanDrop = true
break
end
end
end
end)
Either your Tool doesn’t have a Parent.Parent or your Configurations is not found. Try running print("Config variable: ", Configurations) to see if it can find Configurations as a child of your Tool.
The other reply WaitForChild("Part", 5) will actually not say “Infinite Yields Possible” but instead just return nil after 5 seconds. This is a useful additional argument but it will not help you in this case.
You don’t need to do this, When getting the Object, Typing in the Name will give you the object with the specified name and will tell you what it is (Class),
Typing in a function, or thread will give you the description of what it does, What Arguments you need to use
While Hovering Over a Instance in the Object Inserter will tell you what that Instance does
You are referring to the editor’s type checking system, it does not reflect the actual state of the game when running. It will usually tell you what type a variable is, it could be wrong, but this can also be null. The correct type of anything returned by :FindFirstChild is Instance? which could be null or any game object. To make better use of this type checking put --!strict at the top of your scripts and look into luau https://luau-lang.org/ strict type checking is also a fantastic tool, but I am getting off topic now.
Try the print statement to confirm your Configurations variable is not null and please post a screenshot of the explorer tree, I am willing to bet there is not a Configurations as the chlid of the author’s tool.
True, but the thing is, the actual game takes time to load in objects while in Editor Mode it doesnt run the script (of course)
When Giving the player the tool, it activates the scripts inside it and moving all the items to the Player, Because of this, it will need time to find the Objects instead of it just firing to immediately look for an object, this is usually the reason for the script not being able to find an object and giving an error, not saying it is the reason, but a possibility
that does make sense. Because the script is saying that an infinite yield is possible. What will this do to my game if I don’t fix it? It does work but it just says that.