Did you try it without the offset and if so where did the respective other players marker show at?
local p2 = actor.rootpart.Position - rootpart.Position --creates a Vector3 from player1 position - player2 postion
local screenPos, onScreen = viewportMap:WorldToViewportPoint(p2) --uses the p2 vector as the world point for player2
Why are you trying to show the point for player2 in single player? I think seeing a little bit more of your code could help.
Each player has a copy of this script that’s displaying it’s minimap?
How many players are there that you want markers for?
From what I can see the current setup should only work for exactly two players, otherwise you need to loop over a list of all players or not run the code at all if in single player.
As for the viewportframes, it would replace your current minimap frame and shows it’s version of the world that only includes the parts parented to the frame.
I haven’t tried this setup to be sure but it should go something like.
-Add a ViewportFrame, position it (probably pointing at the player), move in-place of the current minimap, hide/remove the current minimap frame, duplicate your map object and parent it to the new viewportFrame, at this point your duplicated map (but nothing else) should be showing in the frame.
-Next add a red sphere (or whatever you want to serve as visual marker for the players) and parent it to the frame. Now that red ball will also show up in the frame (won’t do anything yet) but not in the “normal” world because we didn’t duplicate it (like the map), we just parented it diectly to the frame which makes that part visible only in the frame.
-The next steps would be to remove the red ball added previously for example purposes, have each player or the server create a clone of the marker when the player joins and keep it informed of the players position. Probably Connect to the RunServices HeartBeat and run the code in there.
marker.Position = player.Position
Now the marker(s) should move around the map in the frame in the same way as the player does, all on it’s own, you won’t need to :WorldToViewportPoint(), it just shows what’s going on in the mini version of the world, be it one or twenty players. Of course, if this is done client side it’s open to exploits but it should work either way.
In Unity, you can define renderlayers and have a camera only show objects assigned to that renderlayer. In this case I would have attached the red sphere (with no collider) directly to the player and set it’s renderlayer to only the minimap layer, which is the only layer the minimap camera would be displaying (the main camera would be set to ignore the minimap layer). I’d also include the terrain/map in the that renderlayer. This way the players in game don’t see the red ball marking their position (It’s there they just can’t see it) but the minimap camera (floating somewhere above the player) can see the map and the player markers but not the players themselves, showing them just as they are on the map.
Using a ViewportFrame in Roblox is the same sort of idea, the frame is the layer and parts parented to the frame are only visible in that frame. The extra you have to do here vs in Unity is coordinate the movements between the player and it’s marker because the marker isn’t directly attached to the player like it is in Unity.
Anyway, hope this helps a bit. When I get some more time I’ll try to get a working example posted.