I would like to make a "country" claiming system

  1. What do you want to achieve?
    A country claiming system, possibly based on the colour of the nation clicked on the map

  2. What is the issue?
    I have no idea on how to make this

  3. What solutions have you tried so far?
    I tried to make a clickdetector that once clicked assign you to premade team that could be Italy in case of Italy (dark green) clicked but it doesn’t seem to be working nor can i make a clickdetector for any part since then it would be clickable by other player assigning it to the same team (Italy).

Any idea so far?

Can we see what code you have so far in term of this clickdetector?

local countryColors = {
[“Country1”] = Color3.new(1, 0, 0), – Red
[“Country2”] = Color3.new(0, 1, 0), – Green
}

local function onMapClick()
local mouse = game.Players.LocalPlayer:GetMouse()
local hitPart = workspace:WaitForChild(“Map”):FindPartOnRay(mouse.UnitRay)
if hitPart then
local clickedColor = hitPart.Color
for country, color in pairs(countryColors) do
if clickedColor == color then
print(game.Players.LocalPlayer.Name … " claimed " … country)
end
end
end
end

game.Players.LocalPlayer:GetMouse().Button1Down:Connect(onMapClick)

As you can see i tried to make it very basic (I’m not an expert in this code language) the team assigning hasn’t been added yet since i’ve seen it doesn’t even print the claimed country thing

local function onMapClick(player)
     local mouse = game.Players.LocalPlayer:GetMouse()
     local hitPart = workspace:WaitForChild(“Map”):FindPartOnRay(mouse.UnitRay)
     if hitPart then
          if player == mapOwner then
               -- put your code below into here
          end

          local clickedColor = hitPart.Color
          for country, color in pairs(countryColors) do
               if clickedColor == color then
                    print(game.Players.LocalPlayer.Name … " claimed " … country)
               end
          end
     end
end

game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function(player)
     onMapClick(player)
end)

From the looks of it, it looks like you’re using a local script for this. This means that the problem you mention about being clickable by other players won’t make any changes because this is a local side changer rather than the server. However, if you are planning to use the server, you can use the modify code I provided above where it checks to see if the player is the owner of the country.

Where should i put it? I used to put it in all parts with clickdetector… is that right?

Where ever you got that code from, I just modify it so it checks if the player clicking it is the owner. Make sure you change mapOwner to the owner of whoever owns the country. Also I think it’s best you using an in pair loop to loop though all the parts with identical children.