Workaround this problem?

Hey there! so, i made a minimap system and ill explain how it works here:

  • Script runs
  • I loop through the map
  • I add map items to the viewport frame
  • Every second, i remove everything from the Viewport frame and i readd it so it updates

Now the problem here is that if a “Special Part” appears i put an arrow near that and that arrow will be clickable but i remove that every “RenderStepped” so it doesn’t function.

So, just don’t remove it? I tried that but it just creates a bunch of arrows since i want it to update

Now my first thought was to create the arrow once, add the name to a table (before that ill make a random name for every one of them to identify them) but i can’t make it work.

heres my code:

RunService.RenderStepped:Connect(function()
	
	for _, v in pairs(Frame:GetChildren()) do
		if v:FindFirstChild("UIDefault") then continue end
		v:Destroy()
	end
	
	for i,Elements in pairs(__MAP:GetChildren()) do 
		local Cloning = Elements:Clone()
		Cloning.Parent = Frame
		
		if Cloning.Name == "Pad" and not table.find(created,Cloning) then
			table.insert(created,Cloning)
			local scale = pointToViewport(Cam,Cloning.Position) --Just a function to know where to put the Arrow, not important in this situation
			
			local charCursor = Frame.Parent:WaitForChild("TPArrow"):Clone()
			charCursor.Parent = Frame
			charCursor.Object.Value = Elements
			
			charCursor.Visible = true
			charCursor.Position = UDim2.new(scale.X, 0, scale.Y, 0)
			
			charCursor.MouseButton1Click:Connect(function()
				print("clicked")
				Character.PrimaryPart.CFrame = charCursor.Object.Value.CFrame
			end)
			
		elseif table.find(created,Cloning) then
			for _, v in pairs(Frame:GetChildren()) do
				if v:FindFirstChild("Object") and v.Object.Value == Elements then
					print("e")
					local scale = pointToViewport(Cam,Cloning.Position)
					
					v.Position = UDim2.new(scale.X, 0, scale.Y, 0)
				end
			end
		end
		
	end
	
	Cam.CFrame = CFrame.new(HumanoidRootPart.Position + Vector3.new(0,4000,0), HumanoidRootPart.Position)
	PlayerArrow.Rotation = -HumanoidRootPart.Orientation.Y + 70
	--PlayerArrow.Rotation = -HumanoidRootPart.Orientation.Y - 90
end)

Also, for anyone wondering, it does not print “e” nor print anything past the "elseif table.find"

Thanks!!

This is inefficient as if a player with an extremely old device would play this, it would have to constantly load the map and remove it every millisecond or whatever. I would connect a RenderStep to face in the direction the character is rotating in. That way, the arrow can point in the direction that is specified.

1 Like

What do you mean by this? chars

What about new parts that are created?

That was the original code i believe, i just create new parts and i need those new parts to be inside the minimap.

I think there’s a function to see if a part is added to a parent right here.

https://developer.roblox.com/en-us/api-reference/event/Instance/ChildAdded

Use this to add it to the viewport.

1 Like

What if its a projectile? Like moving?

Then I would loop through it and constantly set its position.

1 Like

So, loop and set the position in the viewport frame? Can i just set the position of the projectile in the viewport frame using the original projectile?

So can i just get the position in the workspace of the projectile and set it to the position of the projectile in the viewport frame or do i have to do some calculation?

Yeah, I think I said that, right?

Yes, but if you’re changing the position of the whole map elsewhere, then you would need some calculating.

1 Like

Also don’t forget, deleting stuff in the workspace wont delete in the viewport, so there’s also a function called ChildRemoved. Remove it on function.

1 Like

How would i identify the cloned part then? Because i can’t use names since there could be different parts that have the same name

Send it to the client via remoteevent with the part

1 Like