I’m making an interactive GUI for multiple tagged items. For some reason, the status of my coroutine always returns the suspended status. It doesn’t yield either, the second resume doesn’t work and only works for the first tagged item.
local Interaction = coroutine.create(function(Frame, KeyText, ActionText, Action, Key, TaggedParts)
RS.Heartbeat:Connect(function()
Frame.Visible = false
for _,item in pairs(TaggedParts) do
if (item.PrimaryPart.Position - humanoid.Position).magnitude <= 6 and mouse.Target == item.PrimaryPart then
Frame.Visible = true
ActionText.Text = Action
KeyText.Text = Key
end
end
coroutine.yield()
end)
end)
coroutine.resume(Interaction, AboveHoverFrame, AboveKey, AboveAction, "Open", "E", Doors)
coroutine.resume(Interaction, BelowHoverFrame, BelowKey, BelowAction, "Dispose", "LMB", Disposables)
I’m not really sure what the point of your coroutine thing is here. If all you’re trying to do is toggle visibility of the UI, you could remove the coroutine stuff and just use the heartbeat loop.
local function Interaction(Frame, KeyText, ActionText, Action, Key, TaggedParts)
RS.Heartbeat:Connect(function()
Frame.Visible = false
for _,item in ipairs(TaggedParts) do
if (item.PrimaryPart.Position - humanoid.Position).Magnitude <= 6 and mouse.Target == item.PrimaryPart then
Frame.Visible = true
ActionText.Text = Action
KeyText.Text = Key
break
end
end
end)
end
Interaction(AboveHoverFrame, AboveKey, AboveAction, "Open", "E", Doors)
Interaction(BelowHoverFrame, BelowKey, BelowAction, "Dispose", "LMB", Disposables)