Values not parenting properly via a module script

Hey yall.

At the moment, I am currently having an issue where an intvalue isn’t being properly parented in a module. I have tested many different debug statements, where in the module it says that it is being parented, but in the ServerScript that checks for the child, it says that it doesn’t exist. This is for a tycoon style game and I was looking to see if anybody has had this issue previously. Here’s my code, Thanks!:

-- Module
function rngmodule.drop(tycoon, dropperType, spawner, player)
    local cashValue = Instance.new("IntValue")
	cashValue.Value = info[2] -- Info2 is NOT nil, as I have checked it previously
	cashValue.Name = "CashValue"
	cashValue.Parent = part -- part is previously defined in this.

	if cashValue.Parent == part then
		print("Successfully parented CashValue to part.") -- This is printing each time this code is ran.
	else
		warn("Failed to parent CashValue to part.") -- hasn't printed since adding
	end

	task.wait()
	game.Debris:AddItem(part, 15)
end

and the other server script:

-- Server Script
local values = script.Parent.Parent.Parent.Parent.Values

script.Parent.Touched:Connect(function(hit)
	if hit.Name == "DropperPart" and hit:IsA("BasePart") then
		local cashValue = hit:FindFirstChild("CashValue")

		if cashValue then
			values.MoneyValue.Value += cashValue.Value
			hit:Destroy()
		else
			print("No value found") -- Prints after about 45 seconds of running every 3-10 parts created.
		end
	end
end)

if you are calling the module on the client than the server can’t see the part the client creates

Nah its called server sided, also it works for a while then breaks.

Where is the module function being callled?

The function is being called from a server script in workspace, and the module is located in Server Storage

How is the part defined previously?

Cause I think it would be better to declare part when you call the function.

Yeah mb wasn’t very clear about that, I cut down the function to the parts where the main issue was because its a big function; The part is created inside of the same function and the code for it is

	local part = Instance.new("Part", dropperPartsFolder)
	part.Size = Vector3.new(1, 1, 1)
	part.Color = info[3]
	part.Material = info[4]
	part.Name = "DropperPart"
	part.CFrame = CFrame.new(Vector3.new(spawner.CFrame.X, spawner.CFrame.Y - 2, spawner.CFrame.Z))

Hey, so I am still working on this; I’ve added print statements to my code & debugged as far as I could, and I couldn’t seem to get it to work properly. The module prints that it is parenting correctly (Added a check in it after its parented to check to see if the value actually exists, which it doesn’t,) and then inside of the touched script, I added a check where it says that the value doesn’t exist. This only happens after about 45 seconds → 3 minutes after the game started and the module begun being used. Maybe something on the Roblox end? Lmk if yall have any ideas.

corrected versions of your module script and server script:

Module Script:

-- Module
function rngmodule.drop(tycoon, dropperType, spawner, player)
    local cashValue = Instance.new("IntValue")
    cashValue.Value = info[2] -- Assuming 'info' is defined elsewhere
    cashValue.Name = "CashValue"
    cashValue.Parent = part -- Assuming 'part' is correctly defined

    if cashValue.Parent == part then
        print("Successfully parented CashValue to part.")
    else
        warn("Failed to parent CashValue to part.")
    end

    task.wait()
    game.Debris:AddItem(part, 15)
end

Server Script:

-- Server Script
local values = script.Parent.Parent.Parent.Parent.Values

script.Parent.Touched:Connect(function(hit)
    if hit.Name == "DropperPart" and hit:IsA("BasePart") then
        local cashValue = hit:FindFirstChild("CashValue")

        if cashValue then
            values.MoneyValue.Value = values.MoneyValue.Value + cashValue.Value
            hit:Destroy()
        else
            print("No value found")
        end
    end
end)

Please make sure to check the definitions and references in your actual game code to ensure that they align with these