Check if contents of a table are touched by the player

I got a problem and i couldn’t find a solution on google. I added save triggers to a table and then looped through it and then checked if they’re being touched by the player, i’m trying to make a save system and i really need help.

Whenever i start the game it print’s out "Attempt to index nil with function “Touched”

Server Script:

local saveTriggers = require(script.SaveTriggers)

for i, object in pairs(saveTriggers) do
	trigger = object
end

trigger.Touched:Connect(function(p)
	if p.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(p.Parent)
		local save = plr:WaitForChild("SaveFolder"):WaitForChild("Save")
		
		saveTriggers.Save(trigger, save)
	end
end)

Module Script:

local saveTriggers = {}
local folder = workspace.SavePoints

for i, trigger in ipairs(folder:GetChildren()) do
	table.insert(saveTriggers, trigger)
end

function saveTriggers.Save(trigger, save)
	save.Value = trigger.Name
end

return saveTriggers

I fixed it, instead of checking if the part is getting touched, i check if the player gets touched and if the part’s parent’s name is “SaveTriggers”.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.