Sorry for the vague title, but i have an idea to change my script to make it “Cleaner” and somewhat better.
Basically how it is now is a loop to find if the guns been purchased
local player = game.Players.LocalPlayer
local SelGui = script.Parent
local Modules = game.ReplicatedStorage:WaitForChild("Modules")
local Events = game.ReplicatedStorage:WaitForChild("Events")
local Inventorys = game.ReplicatedStorage:WaitForChild("InvHolder")
local PlayerFolder = Inventorys:WaitForChild(player.Name .. "DataFolder")
local GunMod = require(Modules.GunShop)
local GunEvent = Events:WaitForChild("ShopEvent")
local PurchaseEvent = Events:WaitForChild("PurchaseEvent")
local EquipEvent = Events:WaitForChild("EquipEvent")
local Image = SelGui:WaitForChild("GunPicture(TEMP)")
local CostText = SelGui:WaitForChild("CostLabel")
local ReqText = SelGui:WaitForChild("ReqLevelLabel")
local PurchaseButton = SelGui:WaitForChild("PurchaseButton")
local EquipButton = SelGui:WaitForChild("EquipButton")
local GunSelected = nil
local function BuyGun(Gun)
if not Gun then return "No Gun Selected" end
if not GunMod[Gun] then return "NoGun" end
PurchaseEvent:FireServer(Gun)
end
local function EquipGun(Gun)
if not Gun then return "Still No Gun" end
if not GunMod[Gun] then return "Gun Doesnt Exist" end
EquipEvent:FireServer(Gun)
end
GunEvent.Event:Connect(function(Gun)
if Gun == GunSelected then
GunSelected = nil
else
GunSelected = Gun
end
end)
PurchaseButton.Activated:Connect(function()
BuyGun(GunSelected)
end)
EquipButton.Activated:Connect(function()
EquipGun(GunSelected)
end)
while wait() do
if GunSelected ~= nil then
Image.Image = if GunMod[GunSelected].PictureId then "http://www.roblox.com/asset/?id=" .. GunMod[GunSelected].PictureId else 0
CostText.Text = GunMod[GunSelected].Cost .. "$"
ReqText.Text = GunMod[GunSelected].LevelReq
if PlayerFolder:WaitForChild("ShopOwned")[GunMod[GunSelected].GunType .. "Guns"]:FindFirstChild(GunSelected) then
local GunType = GunMod[GunSelected].GunType
if PlayerFolder.Game["Equipped" .. GunType].Value == GunSelected then
EquipButton.Visible = true
EquipButton.Text = "UnEquip"
else
EquipButton.Visible = true
EquipButton.Text = "Equip"
end
else
PurchaseButton.Visible = true
end
else
Image.Image = 0
CostText.Text = " "
ReqText.Text = " "
PurchaseButton.Visible = false
EquipButton.Visible = false
end
end
Ya know, mainly so if they purchase / equip the gun they dont have to reclick the guns button to see the new equip / unequip button
Although im pretty sure someone mentioned another way i could do it in another thread which ive been thinking about
I was thinking to use RemoteFunctions and return values if the player bought the gun / if they equipped / if they unequipped and just change the button depending on the returned value (Basically getting rid of the need of a loop), although i dont know if this is would benefit the code for the better or for the worse
(edit)
Added more information i left out