Hello! I’m making an RNG game and I don’t have a way to delete auras from your inventory, i’ve been struggling with this for a WHILE now and I would really like some help.
So basically I need it to not only take the billboard gui and attachment out of the players body, but also remove it from the inventory ui (has to be handled from playergui) which looks like this:
The code inside the delete button: (WHICH IS A SCRIPT, NOT A LOCAL SCRIPT)
Button Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipEffectEvent = ReplicatedStorage:WaitForChild("EquipEffect")
local Delete = script.Parent
local ScrollingFrame = Delete.Parent.ScrollingFrame
Delete.MouseButton1Up:Connect(function()
local selectedEffect = nil
-- Find the selected effect in the ScrollingFrame
for _, v in pairs(ScrollingFrame:GetChildren()) do
if v:IsA("TextButton") and v.BackgroundTransparency == 0.75 then
selectedEffect = v
break
end
end
-- Fire a server event to delete the selected effect
EquipEffectEvent:FireServer("Delete", selectedEffect.Name)
end)
The “equip” script that handles both deleting (which doesnt work) and equipping:
Equip Script
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("PlayerData")
local ServerStorage = game:GetService("ServerStorage")
local EquipEffectEvent = game:GetService("ReplicatedStorage"):WaitForChild("EquipEffect")
local GlobalData = ServerStorage:WaitForChild("PlayerData")
local Effects = ServerStorage:WaitForChild("Auras")
-- Function to load player data
local function loadPlayerData(player)
local playerFolder = Instance.new("Folder")
playerFolder.Name = player.UserId
playerFolder.Parent = GlobalData
local inventoryFolder = Instance.new("Folder")
inventoryFolder.Name = "Inventory"
inventoryFolder.Parent = playerFolder
local equippedFolder = Instance.new("Folder")
equippedFolder.Name = "CurrentlyEquipped"
equippedFolder.Parent = playerFolder
local success, data = pcall(function()
return PlayerDataStore:GetAsync(player.UserId)
end)
if success and data then
-- Load inventory
for _, itemName in ipairs(data.Inventory or {}) do
local item = Instance.new("StringValue")
item.Name = itemName
item.Parent = inventoryFolder
end
-- Load currently equipped items
for _, equippedItem in ipairs(data.CurrentlyEquipped or {}) do
local item = Instance.new("StringValue")
item.Name = equippedItem
item.Parent = equippedFolder
end
-- Equip the currently equipped items
for _, item in pairs(equippedFolder:GetChildren()) do
equip(player, item.Name, equippedFolder)
end
end
end
-- Function to save player data
local function savePlayerData(player)
local playerFolder = GlobalData:FindFirstChild(player.UserId)
if playerFolder then
local inventory = {}
local currentlyEquipped = {}
for _, item in pairs(playerFolder.Inventory:GetChildren()) do
table.insert(inventory, item.Name)
end
for _, item in pairs(playerFolder.CurrentlyEquipped:GetChildren()) do
table.insert(currentlyEquipped, item.Name)
end
local data = {
Inventory = inventory,
CurrentlyEquipped = currentlyEquipped
}
pcall(function()
PlayerDataStore:SetAsync(player.UserId, data)
end)
end
end
-- Equip and unequip functions
local function delete(player, selectedEffect, CurrentlyEquippedFolder)
local head = player.Character:FindFirstChild("Head")
local torso = player.Character:FindFirstChild("Torso")
if head and torso and selectedEffect then
for _, v in pairs(head:GetChildren()) do
if v.Name == selectedEffect or v:IsA("BillboardGui") or v:IsA("Attachment") then
v:Destroy()
end
end
for _, v in pairs(torso:GetChildren()) do
if v.Name == selectedEffect or v:IsA("BillboardGui") or v:IsA("Attachment") then
v:Destroy()
end
end
CurrentlyEquippedFolder:ClearAllChildren()
end
end
function equip(player, selectedEffect, CurrentlyEquippedFolder)
local effect = Effects:WaitForChild(selectedEffect)
local title = effect:WaitForChild("Head"):WaitForChild(selectedEffect):Clone()
local particles = effect:WaitForChild("Torso"):WaitForChild(selectedEffect):Clone()
local character = player.Character or player.CharacterAdded:Wait()
title.Parent = character.Head
particles.Parent = character.Torso
local stringVal = Instance.new("StringValue")
stringVal.Name = selectedEffect
stringVal.Parent = CurrentlyEquippedFolder
end
-- Main equipEffect function
local function equipEffect(player, operationType, selectedEffect)
local PlayerDataFolder = GlobalData:WaitForChild(player.UserId)
local InventoryFolder = PlayerDataFolder:WaitForChild("Inventory")
local CurrentlyEquippedFolder = PlayerDataFolder:WaitForChild("CurrentlyEquipped")
if operationType == "Equip" and selectedEffect then
if InventoryFolder:FindFirstChild(selectedEffect) then
if #CurrentlyEquippedFolder:GetChildren() ~= 0 and CurrentlyEquippedFolder:GetChildren()[1].Name ~= selectedEffect then
delete(player, CurrentlyEquippedFolder:GetChildren()[1].Name, CurrentlyEquippedFolder)
end
if #CurrentlyEquippedFolder:GetChildren() == 0 or CurrentlyEquippedFolder:GetChildren()[1].Name ~= selectedEffect then
equip(player, selectedEffect, CurrentlyEquippedFolder)
end
end
elseif operationType == "delete" and selectedEffect and CurrentlyEquippedFolder:FindFirstChild(selectedEffect) then
delete(player, selectedEffect, CurrentlyEquippedFolder)
end
end
-- Connect equipEffect function to the event
EquipEffectEvent.OnServerEvent:Connect(equipEffect)
-- Load data when player joins
Players.PlayerAdded:Connect(function(player)
loadPlayerData(player)
end)
-- Save data when player leaves
Players.PlayerRemoving:Connect(function(player)
savePlayerData(player)
end)
If you need anything else like resources or more context, I’m online. But please help me lol.
Thanks sososoos much!
Antlers