So, after finally getting my rank shop code to not error, I now face another annoying issue. For some reason, when I want to purchase a rank and I click the purchase button, it freezes up studio; Most of the time it causes it to crash, but one time it didn’t, but instead it took excess cash from my cash value within the player, and I’m stuck on what could be causing it. I know for definite that the shop is causing this though. Help?
Code:
local allNames = require(game.ReplicatedStorage.ListOfAllRanks)
local player = game.Players.LocalPlayer
local CurrentlyEquipped = player:WaitForChild("CE")
local buttons = {}
local owned = {}
game.ReplicatedStorage.SendOwnedThings.OnClientEvent:Connect(function(ownedStuff)
owned = ownedStuff
end)
for i, v in pairs(allNames) do
local Button = Instance.new("TextButton", script.Parent)
Button.BackgroundColor3 = Color3.new(1, 0.333333, 0)
Button.BorderColor3 = Color3.new(1, 0.333333, 0)
Button.TextColor3 = Color3.new(1, 1, 1)
Button.TextScaled = true
Button.Font = "PermanentMarker"
Button.Name = tostring(i)
local UiCorner = Instance.new("UICorner", Button)
table.insert(buttons, #buttons+1, Button)
Button.Text = v.Name
local HasGot = Instance.new("BoolValue", Button)
HasGot.Name ="HasGot"
HasGot.Value = false
local Price = Instance.new("IntValue", Button)
Price.Name = "Price"
Price.Value= v.Price
end
if owned ~= nil then
for _, v in pairs(buttons) do
for _, o in pairs(owned)do
if v.Text == o then
v:WaitForChild("HasGot").Value = true
end
end
end
end
function EquipFire(text)
game.ReplicatedStorage.EquipRank:FireServer(text)
end
function ifConfirm(stringGiven, price)
game.ReplicatedStorage.BuyRank:FireServer(price)
script.Parent.Parent["Buy/Equip"].Text = "Equip"
script.Parent.Parent["Buy/Equip"].TouchTap:Connect(function()
EquipFire(stringGiven)
end)
script.Parent.Parent["Buy/Equip"].MouseButton1Down:Connect(function()
EquipFire(stringGiven)
end)
if owned~= nil then
table.insert(owned, #owned+1, stringGiven)
else
local tb = {}
table.insert(tb, #tb+1, stringGiven)
owned = tb
end
for i , v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextButton") then
if v.Text== stringGiven then
v:WaitForChild("HasGot").Value =true
end
end
end
game.ReplicatedStorage.UpdateOwned:FireServer(owned)
script.Parent.Parent["Buy/Equip"].MouseButton1Down:Connect(EquipFire(stringGiven))
end
function Touched(button)
if not button:WaitForChild("HasGot").Value then
script.Parent.Parent.SelectedOneHere.Text = button.Text
script.Parent.Parent["Buy/Equip"].Text = "Do You Want To Buy this?"
script.Parent.Parent.Price.Text = "Price = "..button.Price.Value
local function OnClick()
ifConfirm(button.Text, button.Price.)
end
script.Parent.Parent["Buy/Equip"].TouchTap:Connect(function()
ifConfirm(button.Text, button.Price.Value)
end)
script.Parent.Parent["Buy/Equip"].MouseButton1Down:Connect(function()
ifConfirm(button.Text, button.Price.Value)
end)
elseif not CurrentlyEquipped.Value == button and button:WaitForChild("HasGot").Value then
script.Parent.Parent.SelectedOneHere.Text = button.Text
script.Parent.Parent["Buy/Equip"].Text = "Unequipped"
elseif CurrentlyEquipped.Value == button.Text and button:WaitForChild("HasGot").Value then
script.Parent.Parent.SelectedOneHere.Text = button.Text
script.Parent.Parent["Buy/Equip"].Text = "Equipped"
end
end
while wait() do
for i, v in pairs(buttons) do
v.TouchTap:Connect(function()
Touched(v)
end)
v.MouseButton1Down:Connect(function()
Touched(v)
end)
end
end