- What do you want to achieve?
When the CardRandom RE is fired, the GUI pops up on the screen and the player can select only one card. The issue is that the model is looking SUPER weird in the Viewport Frame and not how it was originally before I added the RE to the script; hence, I believe my script to be the cause of this issue.
I also want it so that each time the RE is fired, the slots will each have a new card, randomized from the Cards folder in RS; the GUI comes onto the screen, the player selects one and the GUI is disabled. I was possibly considering making the GUI clone from RS each time the RE is fired, then when the card is selected, the cloned GUI is destroyed… but again, this has been an absolute pain to accomplish.
- What is the issue?
You can see a video of the issue here: cardselectionissues.mov on Vimeo
Basically, the rotation is acting strange; however, as I said before… this started happening after I added the RE function to the script.
- What solutions have you tried so far?
I’ve spent days trying to figure this out, rewriting the entire script (as you can see in the video, I’ve created multiple versions to test out different scenarios.
Workspace Screenshots:
Let me know if you need more information!
Script:
local function playSound()
script.AddSound:Play()
end
-- Get the ItemDesc object from the parent of the script
local Info = script.Parent.ItemDesc
-- Loop through each slot in the grid
for i, slot in ipairs(script.Parent.Slots:GetChildren()) do
-- Check if the slot is a Frame object
if slot:IsA("Frame") then
-- Add a MouseEnter event listener to the slot
slot.MouseEnter:Connect(function()
-- Get the first child of the ViewportFrame.Model and set the ItemName object in the Info variable to its Name property
local firstChild = slot.ViewportFrame.Model:GetChildren()[1]
Info.ItemName.Text = firstChild.Name
Info.ItemDescription.Text = firstChild:FindFirstChild("Desc").Value
-- Set the Visible property of the Info object to true
Info.Visible = true
end)
-- Add a MouseLeave event listener to the slot
slot.MouseLeave:Connect(function()
-- Set the Visible property of the Info object to false
Info.Visible = false
end)
--Define a function to equip a random card in the slot
local function equipRandomCard()
local cardsFolder = game.ReplicatedStorage.Cards
local randomCard = cardsFolder:GetChildren()[math.random(1, #cardsFolder:GetChildren())]
local clonedCard = randomCard:Clone()
clonedCard.Parent = slot.ViewportFrame.Model
script.Parent.Parent.Parent.Enabled = true
end
-- Listen for the CardRandom remote event and equip a new random card when it is fired
game.ReplicatedStorage.InvEvents.CardRandom.OnClientEvent:Connect(function()
equipRandomCard()
end)
end
end
--/Slots
local slotframe = script.Parent.Slots
local function update(specific)
-- Get a reference to the Cards folder in ReplicatedStorage
local cardsFolder = game.ReplicatedStorage.Cards
-- Get a random child from the Cards folder
local randomCard = cardsFolder:GetChildren()[math.random(1, #cardsFolder:GetChildren())]
-- Clone the random card and set its parent to the ViewportFrame.Model property of the specific slot
local clonedCard = randomCard:Clone()
clonedCard.Parent = slotframe:FindFirstChild(specific).ViewportFrame.Model
-- Disable and re-enable the RotateVis script under the specific slot's parent
local rotateVis = slotframe:FindFirstChild(specific).RotateVis
rotateVis.Disabled = true
rotateVis.Disabled = false
end
local slots = script.Parent.Slots
--// glowing selection reset
slots.Primary.ImageButton.Transparency =1
slots.Secondary.ImageButton.Transparency = 1
slots.Tertiary.ImageButton.Transparency = 1
local equipped = true
-- Loop through each slot in the grid
for i, slot in ipairs(script.Parent.Slots:GetChildren()) do
-- Check if the slot is a Frame object
if slot:IsA("Frame") then
-- Add a MouseClick event listener to the slot
slot.ImageButton.MouseButton1Click:Connect(function(player) --added player
-- Get the first child of the ViewportFrame.Model and set the itemName variable to its Name property
local itemModel = slot.ViewportFrame.Model:GetChildren()[1]
local itemName = itemModel.Name
-- Check if the slot has an item equipped
if equipped == true then
local event = game.ReplicatedStorage.InvEvents.PickUp
local item = itemName
local firstChild = itemModel
local itemdescription = firstChild:FindFirstChild("Desc").Value
event:FireServer(item, itemdescription)
-- Set the Equipped value of the item to false and hide the item in the slot
equipped = false
slot.Visible = false
-- Clear the model of the slot to remove the item from the slot
slot.ViewportFrame.Model:ClearAllChildren()
-- Update the value in the settings for the slot
if slot == slotframe.Primary then
script.Parent.Settings.Primary.Value = ''
elseif slot == slotframe.Secondary then
script.Parent.Settings.Secondary.Value = ''
elseif slot == slotframe.Tertiary then
script.Parent.Settings.Tertiary.Value = ''
end
-- Play a sound
playSound()
script.Parent.Parent.Parent.Enabled = false
end
end)
end
end