So,
I made the script to clone an ImageButton
(Hint- It’s an inventory system).
Now, the script is too long, so I’ll only spare you the stress,
and show you the important part.
if v:IsA("Tool") then
local NewSlot = slot:Clone()
NewSlot.Parent = Frame
NewSlot.Name = v.Name
local Name = v.Name
NewSlot.OccupiedImage.Visible = true
NewSlot.ImageLabel.Image = v.TextureId
NewSlot.Occupied.Value = false
local ToolImage = v.TextureId
for i,f in pairs(Indicators) do
if f:IsA("ImageButton") then
if f.Occupied.Value == false then
f.Occupied.Value = true
f.OccupiedImage.Visible = true
f.ImageLabel.Image = ToolImage
f.Name = Name
break
end
end
end
this should work, right?
well technically, yes.
On the other side, however, there’s another script in each of those slots being cloned.
local desc = Holder.InformationContainer.InfomationBox.Description
slot.MouseEnter:Connect(function()
Header.Text = slot.Name
desc.Text = slot.Value.Value
InfoHandler.Visible = true
InfoHandler.Position = UDim2.new(slot.Position)--this is the position of the slot
end)
slot.MouseLeave:Connect(function()
InfoHandler.Visible = false
end)
Shouldn’t this script move ‘Info Handler’ to the position of the duplicated slots?
I mean, the script(local script) is duplicated with the slot, right?
…right?
…Wrong.
Here’s what happens.
If any of the two videos are loaded, then, well,
the place where the InformtionHolder is loading is the location of the first slot.
Now, the question,
How do I make the thing appear on the current slot?
By the way, there is a UIGridLayout in the parent.
Any help will be appreciated.
I’m just too tired to try and find the solution myself.
Thank you.
(P.S I know the code is a quite messy so any improvements will be appreciated)
I’m not gonna lie I had difficulty trying to understand this but you did mention you’re tired, try one of these two things and see if either of them solves your problem,
1 ) Move newSlot.Parent below every edits made to newSlot, this is under the suspicion that the localscript ran before the slot is moved at all, thus returning the initial position. It may not be the solution given that you are using gridlayout to move em, nonetheless it’s still worth a try and if it doesn’t solve, it’s still good practice to edit properties of an instance before parenting it.
2 ) This is most likely your issue, move infoHandler to the AbsolutePosition of the slot instead of the Position, returning .Position is most likely returning UDim2.new(0,0,0,0) thus the issue you’re facing rn
InfoHandler.Position = UDim2.new(slot.AbsolutePosition)
-- and then printed both the position and the absolute position and i got this
00:12:46.639 959.140625, 318.156433 {0, 0}, {0, 0} - Client - LocalScript:13
which means it acknoledges the slots absolute position but doesnt change the infohandlers position
Interesting, here is an alternative way to do this which could work in this case:
local SlotAbsolutePosition = slot.AbsolutePosition
InfoHandler.Position = UDim2.new(0, SlotAbsolutePosition.X, 0, SlotAbsolutePosition.Y)
In this case we are generating a new UDim2 from the slots absolute position. (Absolute position is a Vector2, so we cant just directly assign it to Position on the infohandler)
local SlotAbsolutePosition = slot.AbsolutePosition
InfoHandler.Position = UDim2.new(SlotAbsolutePosition.X, 0, SlotAbsolutePosition.Y, 0)
The X and Y components of a UDim2 “Position” property value are capitalised. Also the first and third values of a UDim2 value represent the scale whereas the second and fourth represent offset. I believe this should be setting the position through scaling as opposed to offsets.
Yea you are right, the font was throwing me off, I actually typed it out with capitals, but i looked at it and it didnt seem right so i changed to lower caps
AbsolutePosition is in pixels, so it should be set via offset not scale.
I was a bit sleepy yesterday as well but I believe @Artoshia already pointed out the UDim2( position ) mistake you made and @Limited_Unique already pointed out the capital error, if regardless of their inputs, this still isn’t working or you’re running into an issue where the infohandler is moved somewhere else, you may want to check the ancestry of infoHandler,
AbsolutePosition is a Vector2, which contains the X and Y position in pixels on the client screen, whereas position is a UDim2 which uses the format of ( X Scale, X Offset, Y Scale, Y Offset ),, however unlike AbsolutePosition, position is local, this means that infoHandler needs to be a child of a frame that is equivalent of the screen bounds or just a direct child of a ScreenGui in order for you to move the offset precisely to another ui’s absoluteposition.
I made a quick example below, nothing fancy, but you get the idea,