- What do you want to achieve?
The RemoteEvent connects to the function every time it’s fired instead of only one time.
- What is the issue?
The RemoteEvent connects to the function the first time it’s fired, but the second time it’s fired, it does not connect. I believe that the issue is within the ItemHandler script since that’s where the function/RE is supposed to connect to.
Video:
- What solutions have you tried so far?
One of my friends tried to help me but the issue still hasn’t been fixed.
I can also guarantee that the issue is due to or at least is related to the RE not connecting to the function a second time since I’ve used prints to determine this.
Screenshot 1
This is from the second use, the “2” is supposed to be printed after it’s connected to the function.
Workspace Screenshots
Note: DisplayEvent RE (RemoteEvent) is located in ShopEvents folder in ReplicatedStorage.
SpecialDisplay
Note: Ignore the “Num” (I forgot to delete it)
Screenshot
ShopGUI
Note: object is parented to “Model” within ViewportFrame
Scripts
ProximityPrompt ServerScript
Note: Ignore the - - out code, that was from me messing around with it.
Script
local cooldown = 1800
local canUse = true
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisplayEvent = ReplicatedStorage.ShopEvents:WaitForChild("DisplayEvent")
--local item = script.Parent.Parent.ObjectDisplay:FindFirstChild()
script.Parent.Triggered:Connect(function(player)
--task.wait(2)
if canUse then
local card_stat = player.Data_Folder.MAX_CARD_STORAGE
local current_card = player.Data_Folder.CurrentCardStorage
local art_stat = player.Data_Folder.MAX_ART_STORAGE
local current_art = player.Data_Folder.CurrentArtStorage
if current_card.Value >= card_stat.Value or current_art.Value >= art_stat.Value then
-- Show the delete message for a few seconds
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = true
player.PlayerGui.GameInventory.DeleteOneMsg.Msg.Text = "You must remove ONE item from your inventory."
wait(2)
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = false
else
if current_card.Value < card_stat.Value or current_art.Value < art_stat.Value then
local selected
for index, value in pairs(script.Parent.Parent.ObjectDisplay:GetChildren()) do
if value:IsA("Model") then
selected = value
DisplayEvent:FireClient(player, selected)
print (value)
print("displayevent fired")
end
end
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = false
-- Hide the delete message if it's still visible
-- Open the card selection GUI
local gui = game.ReplicatedStorage.GUIs.SpecialShopGUI:Clone()
gui.Parent = player.PlayerGui
end
end
canUse = false
script.Parent.Enabled = false
wait(cooldown)
canUse = true
script.Parent.Enabled = true
end
end)
ItemHandler ClientScript
Note: Ignore the - - out code, that was from me messing around with it.
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisplayEvent = ReplicatedStorage.ShopEvents:WaitForChild("DisplayEvent")
local function playSound()
script.AddSound:Play()
end
-- Get the ItemDesc object from the parent of the script
local Info = script.Parent.ItemDesc
DisplayEvent.OnClientEvent:Connect(function(item)
print("Event")
repeat task.wait() until item --added
-- 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
local newItem = item:Clone()
newItem.Parent = slot.ViewportFrame.Model
print(newItem.Name.."parented")
script.Parent.Slots.Cost.Text = "Coins: ".. newItem:FindFirstChild("Cost").Value --added
slot.MouseEnter:Connect(function()
--local newItem = item:Clone()
print (newItem)
-- Get the first child of the ObjectDisplay part and set the ItemName object in the Info variable to its Name property
Info.ItemName.Text = newItem.Name
Info.ItemDescription.Text = newItem:FindFirstChild("Desc").Value
-- Clone the first child and set its parent to the ViewportFrame.Model property of the specific slot
-- newItem.Parent = slot.ViewportFrame.Model
-- print(newItem.Name.."parented")
-- 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)
local slotframe = script.Parent.Slots
local function update(specific)
-- 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
--update()
local slots = script.Parent.Slots
--// glowing selection reset
slots.Primary.ImageButton.Transparency =1
local equipped = true
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)
-- 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
local player = game.Players.LocalPlayer
print(player) -- This will print the value of player in the console
print(player.leaderstats)
-- Check if the slot has an item equipped
local shopitem = itemModel
local itemcost = shopitem:FindFirstChild("Cost").Value
if equipped == true and itemcost > player.leaderstats:FindFirstChild("Coins").Value then
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = true
player.PlayerGui.GameInventory.DeleteOneMsg.Msg.Text = "You don't have enough coins."
wait(2)
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = false
else
if equipped == true and itemcost <= player.leaderstats:FindFirstChild("Coins").Value then
local event = game.ReplicatedStorage.InvEvents.PickUp
local purchaseitem = game.ReplicatedStorage.ShopEvents.Purchase
local item = itemName
local firstChild = itemModel
local itemdescription = firstChild:FindFirstChild("Desc").Value
event:FireServer(item, itemdescription)
purchaseitem:FireServer(itemcost)
-- 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 = ''
end
end
-- Play a sound
playSound()
script.Parent.Parent.Parent:Destroy()
end
end)
end
end
end
end
end)
I really appreciate your help, you all are extremely talented and smart
Also, if you’d prefer to do TeamCreate, please let me know.