Every time I try to touch anything inside game.Workspace.Cubes it would give me an error saying Attempt to call a nil value
, I don't what line is making the error but it would bring me to line 4.
local Provider = require(game.ServerScriptService.DataProvider) local function onTouched(part) local player = game.Players:GetPlayerFromCharacter(part.Parent) if player then local data = Provider:Get(player) if data then table.insert(data.collected,#data.collection + 1,part.Name) print("Player"..player.UserId.."Found"..part.Name) end end end for _, v in pairs(game.Workspace.Cubes:GetChildren()) do if v:IsA("BasePart") then v.Touched:Connect(onTouched(v)) end end
I find get player from character buggy. Get player from character's parameter is supposed to be the character model a player has.
local Provider = require(game.ServerScriptService.DataProvider) local function onTouched(part) local player = game.Players[part.Parent.Name] if player then local data = Provider:Get(player) if data then table.insert(data.collected,#data.collection + 1,part.Name) print("Player"..player.UserId.."Found"..part.Name) end end end for _, v in pairs(game.Workspace.Cubes:GetChildren()) do if v:IsA("BasePart") then v.Touched:Connect(onTouched()) end end
I beleive that part was glitching because the extra v in "v.Touched:Connect(onTouched(v))" which set a nil parameter, and partr was called on line 4 but was nil.