I am trying to make my own inventory system I want to have a gui that pops up when you try to use an item asking if you want to use the item. The problem is that I have the creation of the gui in a function and when you press the confirm or deny button on the frame it is suppose to return true or false but it always returns nil as soon as the frame is created rather than waiting for the buttons to be pressed.
Confirmation gui creation:
local function UseConfirmation(Item)
local newConfirmFrame = script.Parent.ConfirmUse:Clone()
newConfirmFrame.TextLabel.Text = "Are you sure you want to use "..Item.Name.."?"
newConfirmFrame.ConfirmButton.Activated:Connect(function()
newConfirmFrame:Destroy()
return true
end)
newConfirmFrame.DeclineButton.Activated:Connect(function()
newConfirmFrame:Destroy()
return false
end)
newConfirmFrame.Visible = true
newConfirmFrame.Parent = script.Parent
end
You press the use button on the item and then it fires the function, this is where it returns nil:
ItemFrame.UseButton.Activated:Connect(function()
print("player using "..Item.Name)
local confirm = UseConfirmation(Item)
print(confirm)
if confirm then
game.ReplicatedStorage.Remotes.UseItem:InvokeServer(Item.Name)
end
end)
Any help would be appreciated!