What do you want to achieve? I am trying to make a script where it controls every dropper in the game all under one script.
What is the issue? The error keeps saying * `attempt to index nil with ‘CFrame’ * on line 16 even though the CFrame of the primary part is not nil.
What solutions have you tried so far? I’ve tried looking for solutions on the devforum but I couldn’t find any that would work.
Code:
local CollectionService = game:GetService("CollectionService")
local Tycoons = game.Workspace.Tycoons
local module = require(game.ServerScriptService.TycoonModule)
for _, dropper in pairs(CollectionService:GetTagged("Dropper")) do
local Tycoon = dropper.Parent.Parent
local BillboardGUI = game.ReplicatedStorage.BillboardGui
local DropperModule = require(game.ServerScriptService.DropperComponents[dropper.Name])
while true do
local purchasesFolder = Tycoon:FindFirstChild("Purchases")
local DropperPartsFolder = Tycoon:FindFirstChild("DropperParts")
if dropper:IsDescendantOf(purchasesFolder) then
if dropper.PrimaryPart.CFrame ~= nil then
module.CreatePart(dropper, BillboardGUI, DropperPartsFolder, DropperModule.Size, DropperModule.Color, DropperModule.Material, DropperModule.Value)
print("spawned")
else
continue
end
end
task.wait(DropperModule.Cooldown)
end
end
Your error indicates that you are trying to find CFrame in nil so nil.CFrame.
Are you sure that dropper, assuming that it is a model, has a PrimaryPart set?
Try adding some debug prints to check if the Primary part isn’t getting changed by another script or if the dropper still even exists.
Let us know what the output is after like 30 seconds of running the game.
local CollectionService = game:GetService("CollectionService")
local Tycoons = game.Workspace.Tycoons
local module = require(game.ServerScriptService.TycoonModule)
for _, dropper in pairs(CollectionService:GetTagged("Dropper")) do
local Tycoon = dropper.Parent.Parent
local BillboardGUI = game.ReplicatedStorage.BillboardGui
local DropperModule = require(game.ServerScriptService.DropperComponents[dropper.Name])
while true do
local purchasesFolder = Tycoon:FindFirstChild("Purchases")
local DropperPartsFolder = Tycoon:FindFirstChild("DropperParts")
if dropper then
print("[0] Got dropper |",dropper:GetFullName())
else
print("[1] Failed to get dropper.")
end
if dropper:IsDescendantOf(purchasesFolder) then
print("[0] Dropper is part of PurchasesFolder |",dropper:GetFullName())
print("[0] Current PrimaryPart (With CFrame) |",dropper.PrimaryPart,tostring(dropper.Primary.CFrame))
if dropper.PrimaryPart.CFrame ~= nil then
module.CreatePart(dropper, BillboardGUI, DropperPartsFolder, DropperModule.Size, DropperModule.Color, DropperModule.Material, DropperModule.Value)
print("spawned")
else
continue
print("[1] Primary part CFrame is not correct.")
end
else
print("[1] Dropper is not part of PurchaseFolder anymore.")
end
task.wait(DropperModule.Cooldown)
end
[0] Got dropper | Dropper2 - Server - New:17
16:50:05.798
[0] Dropper is part of PurchasesFolder | Dropper2
after i claim a tycoon, it now prints
[0] Got dropper | Dropper2 - Server - New:17
16:50:05.798
[0] Dropper is part of PurchasesFolder | Dropper2
ServerScriptService.TycoonScripts.New:23: attempt to index nil with ‘CFrame’
Are you sure the dropper is part in workspace?
Since the debug print was “GetFullName()” And it was meant to show “game.Workspace…” But it just shows Dropper2. Meaning the dropper might be in nil, Indeed meaning it cannot find a Primary part.
Maybe try setting the dropper to workspace.