Idk man, my code is not working (idk how to explain)

i have no idea what to say about it. idk how to explain im also tired

local SellFolder = script.Parent.PartSell.Selling
local Shared = game.ReplicatedStorage:WaitForChild("SharedCash")


script.Parent.Doohickey.Sell.Event:Connect(function()
	print("HAASDAOIGFASDUSDFGASAFDGHSDFAHJ")
	for _, v in SellFolder:GetChildren() do
		if v.Parent:IsA("Model") then
			if v.Name == "Engine" then
				Shared += 10
			elseif v.Name == "Tank" then
				Shared += 10
			elseif v.Name == "Battery" then
				Shared += 5
			elseif v.Name == "HeadLights" then
				Shared += 5
			elseif v.Name == "Hood/Trunk" then
				Shared += 5
			elseif v.Name == "Console" then
				Shared += 15
			elseif v.Name == "Cabin" then
				Shared += 20
			elseif v.Name == "Board" then
				Shared += 2
			elseif v.Name == "Seat" then
				Shared += 5
			elseif v.Name == "Stick" then
				Shared += 1
			else
				Shared += 1
			end
			v:Destroy()
			print("TeeHee")
		end
	end
end)

“print(“HAASDAOIGFASDUSDFGASAFDGHSDFAHJ”)” works fine
“print(“TeeHee”)” does not work

1 Like

Are there any errors in the output that appear when the code is run?

1 Like

no there is not. sorry for my poor explanation im tired

1 Like

you’re getting v from here

And so it seems like v.Parent isn’t a model but it’s a folder AKA SellFolder if you didn’t catch what I meant yet (so it’s not getting past the first check)

1 Like

it seems as the v.Parent check isn’t going through, could you show us what SellFolder would look like?

there would also be an error as you’re trying to add a number to an instance
did you mean to do Shared.Value += 10 instead of Shared += 10?

2 Likes

sorry i was petting cat fella
sell folder gets filled with models ready to be sold
MODELS ONLY no parts alowed!!!

1 Like

It seems like you intended to check if v is a Model or not.

Try changing this to if v:IsA("Model") then

1 Like

if it’s only models, then this should be the code for the loop

    local COST_MAP = {
        Engine = 10,
        Tank = 10,
        Battery = 5,
        HeadLights = 5,
        ["Hood/Trunk"] = 5,
        Console = 15,
        Cabin = 20,
        Board = 2,
        Seat = 5,
        Stick = 1,
    }

    local SellFolder = script.Parent.PartSell.Selling
    local Shared = game.ReplicatedStorage:WaitForChild("SharedCash")

    script.Parent.Doohickey.Sell.Event:Connect(function()
        print("HAASDAOIGFASDUSDFGASAFDGHSDFAHJ")
        for _, v in SellFolder:GetChildren() do
            if v:IsA("Model") then
                Shared.Value += COST_MAP[v.Name] or 1
                v:Destroy()
                print("TeeHee")
            end
        end
    end)

also cleaned up ur code a bit using a lookup table

2 Likes

im tired im sorry, ill fix tjat

1 Like

bro thank you so much for optimizing it i didnt know how to

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