I’m making a game that looks vaguely like HoI4. So in the game you need to capture other people’s provinces and the leaderboard should show the exact number of provinces owned by the player.
When a player steps on a square (province), it is colored in his color and this cell is assigned a value with the player’s nickname.
I need to make sure that when the player attacks an already occupied province, the enemy has -1 province.
But for some reason it doesn’t work.
Here’s my script, thanks in advance.
local Players = game:GetService("Players")
script.Parent.Touched:connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid")then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if script.Parent.BrickColor ~= player.TeamColor and script.Parent.Player.Value ~= player.Character then
player.leaderstats.Provinces.Value = player.leaderstats.Provinces.Value + 1
script.Parent.BrickColor = player.TeamColor
script.Parent.Player.Value = player.Character
local enemyname = script.Parent.Player
local enemy = Players:FindFirstChild(enemyname.Value)
print(enemyname.Value)
enemy.leaderstats.Provinces.Value = enemy.leaderstats.Provinces.Value - 1
end
end
end)
Why are you comparing a value and a Instance (script.Parent.Player.Value ~= player.Character)? I’m assuming you’re storing the Player’s username, so you should change this part to:
if script.Parent.BrickColor ~= player.TeamColor and script.Parent.Player.Value ~= player.Character.Name then
(rest of the code isnt working because of this error)
As far I know player is defined propely. Can you show me the code that creates leaderstats folder and provinces value ?
local Players = game:GetService("Players")
script.Parent.Touched:connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid")then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if script.Parent.BrickColor ~= player.TeamColor and script.Parent.Player.Value ~= player.Character then
player.leaderstats.Provinces.Value = player.leaderstats.Provinces.Value + 1
script.Parent.BrickColor = player.TeamColor
script.Parent.Player.Value = player.Character
local enemyname = script.Parent.Player.Value
local enemy = Players:FindFirstChild(enemyname)
print(enemyname.Value)
enemy.leaderstats.Provinces.Value = enemy.leaderstats.Provinces.Value - 1
end
end
end)
now its shows It cant find leaderstats folder. You shared me leaderstats script before. Check if you didnt add/remove something in it by mistake during copying script here
local Players = game:GetService("Players")
script.Parent.Touched:connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid")then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if script.Parent.BrickColor ~= player.TeamColor and script.Parent.Player.Value ~= player.Character then
player.leaderstats.Provinces.Value = player.leaderstats.Provinces.Value + 1
script.Parent.BrickColor = player.TeamColor
script.Parent.Player.Value = player.Character
local enemyname = script.Parent.Player.Value
local enemy = Players:FindFirstChild(enemyname)
print(enemyname)
enemy.leaderstats.Provinces.Value = enemy.leaderstats.Provinces.Value - 1
end
end
end)