Help with script from tutorial

I am following a tutorial on how to make a tycoon, the person in the tutorial uses a part as a button but i use a model.
He explains how to do it with a model too but i think he forgot this part.
image
Here’s the script:

local Plots = game.Workspace.Plots

local TemplateWarehouse = game.Workspace.TemplateWarehouse

game.Players.PlayerAdded:Connect(function(player)
	for _, plot in Plots:GetChildren() do
		if plot:GetAttribute("Taken") then continue end
		plot:SetAttribute('Taken', true)
		plot:SetAttribute('Owner', player.UserId)
		
		print('Plot has been given to '..player.Name..'!')
		
		local ItemsFolder = Instance.new('Folder')
		ItemsFolder.Name = 'Items'
		ItemsFolder.Parent = plot
		
		local ButtonsFolder = Instance.new('Folder')
		ButtonsFolder.Name = 'Buttons'
		ButtonsFolder.Parent = plot
		
		local TemplateButtons = TemplateWarehouse.Buttons:Clone()
		local TemplateItems = TemplateWarehouse.Items
		
		for _, Button in TemplateButtons:GetChildren() do
			local RelativeCFrame = TemplateWarehouse:GetPivot():ToObjectSpace(Button:GetPivot())
			Button:PivotTo(plot:GetPivot():ToWorldSpace(RelativeCFrame))
			
			Button.Touched:Connect(function(hit)
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if not player then return end
				if plot:GetAttribute('Owner') ~= player.UserId then return end
				
				local itemToUnlockId = Button:GetAttribute('IdOfItemToUnlock')
				if not itemToUnlockId then warn ('You forgot to add an IdOfItemToUnlock attribute') return end
				
				for _, item in TemplateItems:GetChildren() do
					if item:GetAttribute('Id') ~= itemToUnlockId then continue end
					local itemClone = item:Clone()
					local itemCFrame
					
					if itemClone:IsA('Model') then
						itemCFrame = itemClone:GetPivot()
					elseif itemClone:IsA('BasePart') then
						itemCFrame = itemClone.CFrame
					end
					local relativeItemCFrame = TemplateWarehouse.CFrame:ToObjectSpace(itemCFrame)
					
					if itemClone:IsA('Model') then
						itemClone:PivotTo(TemplateWarehouse.CFrame:ToWorldSpace(relativeItemCFrame))
					elseif itemClone:IsA('BasePart') then
						itemClone.CFrame = TemplateWarehouse.CFrame:ToWorldSpace(relativeItemCFrame)
					end
					
					itemClone.Parent = ItemsFolder
				end
			end)
			Button.Parent = ButtonsFolder
		end
		TemplateButtons.Parent = plot
		break
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	for _, plot in Plots:GetChildren() do
		if plot:GetAttribute("Owner") then continue end
		if plot:GetAttribute("Owner") ~= player.UserId then continue end
		plot:SetAttribute('Taken', nil)
		plot:SetAttribute('Owner', nil)
		
		print('Plot has been removed from '..player.Name..'!')
		break
	end
end)

print TemplateButtons, it might be that your not setting the parent of the clone.

2 Likes

Where can i see that i set the parent of the clone

You haven’t, find this line:

local TemplateButtons = TemplateWarehouse.Buttons:Clone()

and add this after it:

TemplateButtons.Parent = workspace -- Your location

then print the TemplateButtons, and also put a print in the for loop, just to check.

I’m not a scripter so i don’t know what the parent should be and also what u mean with “print the templatebuttons”.

print(templateButtons)
(its not thard lol)


3 Likes

its better to hire a scripter than doing something you don’t know how to do.

Anyway, just copy the code I told you to do above, and print the template buttons with this:

print(templateButtons)

just what I set in the comment above:

for now, at least.

Add an invisible uncollidable part over the button and name it something different or make it he primaryPart of the model

Buttons.Button["Touch Part"].Touched:Connect(function ())
Or whatever else you wanna call the part

Touched is an event of a BasePart, not a model, so we make a Part that covers the entire model, for convenience sake (you can also just use a part of the model, i just prefer this option) to fire the .Touched event

Edit:Typo in code oops

2 Likes

We shouldn’t be discouraged from learning something new, everyone was a beginner at some point, mistakes and struggling are a crucial part of learning.

image
still didn’t fix the problem tho

Your right, we shouldn’t, but I would first focus on learning at least a little bit of scripting before actually making a game like OP is.

Its fine to learn new things, just not jump into your dream game when you barely even know what a parent is.

What does TemplateButtons print? And set it to workspace for now, unless its clashing with other elements.

Print doesn’t functionally do anything search the output window on the view tab, same place where errors appear, and you will see whatever you put within the Print() statement

1 Like

Yeah, it’s something everyone has gone through, deciding to finally do their dream game without realizing how hard it was actually gonna be

I’d argue it’s at least better than just being in tutorial hell watching video after video without making anything

1 Like

ye, it’s always better to make failing games instead of no games

if i am correct, this error msg means that the Touched event doesn’t exist in models
instead, u can use the Touched event on a child of the model or cover the model with an invisible box like what Uri said

2 Likes

ye i’m doing that right now but i don’t understand why Skellyton told me to add this
image

Clones have to be parented to something to work.

local c = workspace.Part:Clone() 
c.Parent = workspace -- Will show up in workspace

local c2 = workspace.Part:Clone() --Wont show up

Where do i need to put or replace this in the script?

The line that causes the error replace the ["Touch part"] with whatever you named your part

Also just so you know it’s formated with these brackets ["Example"] because it has a space in the name, and it errors if you write it like Example.Example Part but they are basically the same otherwise