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

nil Value for something that exists?

The error says "ServerScriptService.game:29: attempt to index nil with 'FindFirstChild' ."

I tried the see if it works without FindFirstChild but that still didn't work.

Here is the script

Local script

local delayTime  = 0.65
local debounce = false
local player = game:GetService("Players").LocalPlayer
local tool = script.Parent

script.Parent.Activated:connect(function(player,tool)
	
	game.ReplicatedStorage.Swing:FireServer()
	
end)

Server Script

local debounce = false
RepStorage.Swing.OnServerEvent:connect(function(player,tool)
	if not debounce then
		debounce = true
		
		tool:FindFirstChild("Handle").Touched:connect(function(hit)
			if hit.Name == "treeHitBox" then
				print("YOU HIT THE TREE")
			end
		end)
		
		
		
		
		debounce = false
	end
end)

Image Link of Explorer

https://lh3.googleusercontent.com/UQuuUybfBMjzkLyW5IAaLTA0WJoYueQBx43ZC5pE-XO0x7XmR8RSnDxz6VGdjmpTD88i=s170

1 comment

0

is everything already defined?

1 answer

I know the problem, its the function that you put in the server script, the function is inside of another function, so you need to make a variable of the function

local debounce = false
RepStorage.Swing.OnServerEvent:connect(function(player,tool)
    if not debounce then
        debounce = true

        local connection = tool:FindFirstChild("Handle").Touched:connect(function(hit)
            if hit.Name == "treeHitBox" then
                print("YOU HIT THE TREE")
            end
        end)



       connection:Disconnect()
        debounce = false
    end
end)

Hope it works!

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