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.
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)
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
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.
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
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
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