Text is not a valid member of Model "Workspace.Store"

Hello. I’m developing a game where you claim a store and sell clothing you made.

Each store has this script:

local store = script.Parent.Parent.Parent
local rentsign = store.ForRentSign

local storeinfo = game.DataStoreService:GetDataStore("StoreInfo")

script.Parent.Triggered:Connect(function(player)
	local owned = player:FindFirstChildWhichIsA("ObjectValue")
	if owned then
		if owned.Value == nil then
			local success, error = pcall(function()
				owned.Value = store
				store.Owner.Value = player.UserId
				
				local data = storeinfo:GetAsync(player.UserId.."_StoreInfo")
				if data then
					wait()
				elseif not data then
					local newdata = {
						255,
						255,
						255,
						player.Name.."'s Store"
					}
					store.Text = newdata[4]
					
					local r = newdata[1]
					local g = newdata[2]
					local b = newdata[3]
					
					for i, paintable in pairs(store.Paintable:GetChildren()) do
						wait()
						if paintable:IsA("Part") then
							paintable.Color = Color3.fromRGB(r,g,b)
						end
					end
					
					store.Text.SurfaceGui.TextLabel.Text = newdata[4]
				end
				game.ReplicatedStorage.Notify:FireClient(player, "Claimed!", 2)
			end)
			if not success then
				game.ReplicatedStorage.Notify:FireClient(player, "Failed to claim store!", 2)
				warn("Failed to claim store : "..error)
			end
		else
			game.ReplicatedStorage.Notify:FireClient(player, "You own a store already!", 2)
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(removing)
	
end)

However, when I trigger the proximity prompt, it just prints this:

But the Text part is a valid member of the Store Model:
Screenshot 2023-02-07 180215

I also tried to print out the Text part and it also failed.

Do you know why this is happening?

2 Likes

You should use WaitForChild, the object may not exist at the time the script is running.

-- Example
local instance = Instance:WaitForChild("ChildName") -- Waits for the child to exist or replicate before doing anything
1 Like

It didn’t work. It just printed the same error. Ima try and move some code from the pcall

1 Like

What does your new code look like?

1 Like

oh wait I forgot about this part of the script

store.Text = newdata[4]

that’s why

A Couple of things,

you shouldn’t use Built In Globals as your Variables, they can hold important info and you would just be overriting it with new info, in this case its error()

instead of using elseif not data then, just use else as it will do the exact same thing, elseif is just adding an extra step.

Instead of using player.Name.."'s Store", you should probably store or keep the UserId of the Player so you can convert it to the Name of the Player, Because if you just change your Username, It wouldn’t add up as it is your previous Username rather than your Current, you can also just get their name without Saving it.

Instead of Checking if paintable is a Part, check if its a BasePart instead.

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