Table Index is nil Problem

hey, so i’ve recently been trying to make this monster with a rake function and a wario apparition type character.

i used this jumpscare free model and when i put it in my monster, it gave me “Workspace.Thom.Test Jumpscare.Script:12: table index is nil”

i’m really not that familiar with tables so i tried searching for a post that related to my problems to no avail.

local jumpscareModule = require(game.ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Jumpscare Manager"))
local debounces = { }
local Players = game:GetService("Players")

script.Parent.Touched:connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if debounces[player] then
		return -- If their debounce is still active then return
	end

	debounces[player] = true
		jumpscareModule.Jumpscare(player)
	wait(4)
	debounces[player] = nil
	end)

any help would be really appreciated

1 Like

Right after the variable player declaration, add the line if player == nil then return end. That should fix the issue.

Basically what is happening is that it is touching parts in the workspace and the function is checking if they are a player. Since the workspace part is not a player, the function returns nil. Trying to use nil as a table index gives you that error. That is my guess.

1 Like

oh, alright thanks for the help!