local cost = 5
local titleVal = Instance.new("StringValue")
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
if player.leaderstats.Wins.Value >= cost then
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost
wait()
script.Parent.Text = "Bought"
titleVal.Name = script.Parent.Parent.Name
titleVal.Parent = player.Inventory
wait(0.1)
script.Parent.Text = "Equip"
print("You bought this title")
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text == "Equip" then
wait()
script.Parent.Text = "Equipped"
player.EquippedTitle.Value = script.Parent.Parent.Name
if script.Parent.Text == "Equipped" then
script.Parent.Text = "Unequipped"
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text == "Unequipped" then
wait()
game.ReplicatedStorage.UnequipTitle:FireServer()
script.Parent.Text = "Equip"
end
end
end --Expected to close line 28 got 'end'
end
end)
Your indentations are ruined, try to indent to make sure the code lines are inside the correct scope, this will lead you to whether your end’s are placed correctly or not.
You made a couple of mistakes in the end sequence as ShutzCh said. Be careful about functions and lining your lines of code properly. I took the liberty of fixing it, but use this as a future example:
local cost = 5
local titleVal = Instance.new("StringValue")
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
if player.leaderstats.Wins.Value >= cost then
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost
wait()
script.Parent.Text = "Bought"
titleVal.Name = script.Parent.Parent.Name
titleVal.Parent = player.Inventory
wait(0.1)
script.Parent.Text = "Equip"
print("You bought this title")
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text == "Equip" then
wait()
script.Parent.Text = "Equipped"
player.EquippedTitle.Value = script.Parent.Parent.Name
if script.Parent.Text == "Equipped" then
script.Parent.Text = "Unequipped"
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text == "Unequipped" then
wait()
game.ReplicatedStorage.UnequipTitle:FireServer()
script.Parent.Text = "Equip"
end
end)
end
end
end)
end
end)