Hi i am getting that syntax error but i can’t fix it.
Can you guys help me with this?
I ran it through an compiler and they all say its in line 11? i checked it 100 times but i cannot find anything. This code is btw for a roblox game.
Code:
local CollectionService = game:GetService('CollectionService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Items = ReplicatedStorage:WaitForChild('Items')
local Tycoons = game.Workspace:WaitForChild('Tycoons')
local PlaceholderTycoon = ReplicatedStorage:WaitForChild('Tycoon')
-- clear all items tycoons
for _, Tycoon in CollectionService:GetTagged('Tycoon') do
if Tycoon:IsDescendantOf(ReplicatedStorage) then continue end
Tycoon.Items:ClearAllChildren()
end
local function GetItemInTycoonById(itemId)
for _, Item in PlaceholderTycoon.Items:GetChildren() do
if Item:GetAttribute('Id') == itemId then
return Item
end
end
end
local function getItem(itemId)
for _, Item in Items:GetChildren() do
if Item:GetAttribute('Id') == itemId then
return Item
end
end
end
local function assignTycoon(player)
for _, Tycoon in Tycoons:GetChildren() do
if Tycoon:GetAttribute("Taken") then continue end
Tycoon:SetAttribute("Taken", true)
Tycoon:SetAttribute("UserId", player.UserId)
return Tycoon
end
end
local function getRelativeCFrame(itemId)
local Item = GetItemInTycoonById(itemId)
local relativeCF = PlaceholderTycoon.PrimaryPart.CFrame:ToObjectSpace(Item:GetPivot())
return relativeCF
end
local function getTycoon(player)
for _, tycoon in game.Workspace.Tycoons:GetChildren() do
if tycoon:GetAttribute('UserId') == player.UserId then
return tycoon
end
end
end
local function unlockedItem(player, itemId)
local tycoon = getTycoon(player)
if not tycoon then return end
local Item = getItem(itemId):Clone()
local Cost = Item:GetAttribute('Cost')
if player.leaderstats.Cash.Value < Cost then
return false
end
player.leaderstats.Cash.Value -= Cost
local RelativeCF = getRelativeCFrame(itemId)
local WorldCF = tycoon.PrimaryPart.CFrame:toWorldSpace(RelativeCF)
Item:PivotTo(WorldCF)
Item.Parent = tycoon.Items
return true
end
for _, Button in CollectionService:GetTagged('Button') do
Button.Touched:Connect(function(hit)
if Button:GetAttribute('Unlocked') then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
local tycoon = getTycoon(player)
if not tycoon then return end
if not Button:IsDescendantOf(tycoon) then return end
local succes = unlockedItem(player, Button:GetAttribute('ItemId'))
if not succes then return end
Button.Transparency = 1
Button.BillboardGui.Enabled = false
Button.SetAttribute('Unlocked', true)
end)
end
game.Players.PlayerAdded:Connect(function(player)
local Tycoon = assignTycoon(player)
if not Tycoon then warn("Could not assign tycoon to "..player.Name) return end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 500
cash.Parent = leaderstats
end)