So, I’m working on a flag that is animated using 16 parts and it is intended to change to display the decal of a British or French flag depending on which team touches the base of the flag.
The Touched interaction works fine and will print it was touched accordingly, except it will print that it was touched by the team color “Really Red (British)” even if I switch to the French team (Really Blue). It also will not print the index of the flag part is changing, as well as does not change the decal accordingly. Script is below.
The execution context (aka path to parts) is correct.
--[[ @mocha______ // @MochaTheDev ]]
local britcolor = "Really Red" -- Color for the British team
local frcolor = "Really Blue" -- Color for the French team
local frflag = 136161583 -- Asset ID for the French flag decal (e.g., asset://1001391838 or the URL for the decal)
local brflag = 8583156400 -- Asset ID for the British flag decal (e.g., asset://1001391838 or the URL for the decal)
local Players = game:GetService("Players")
local flagmodel = script.Parent.Flag
local flagparts = {flagmodel.a, flagmodel.b, flagmodel.c, flagmodel.d, flagmodel.e, flagmodel.f, flagmodel.g, flagmodel.h, flagmodel.i, flagmodel.j, flagmodel.k, flagmodel.l, flagmodel.m, flagmodel.n, flagmodel.o, flagmodel.p}
script.Parent.base.Touched:Connect(function(touched)
if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
local Player = Players:GetPlayerFromCharacter(touched.Parent)
if Player then
print("Flag Touched by", Player.TeamColor)
if Player.TeamColor == britcolor then
for i, v in pairs(flagparts) do
v.TextureID = brflag
print(i)
end
elseif Player.TeamColor == frcolor then
for i, v in pairs(flagparts) do
v.TextureID = frflag
print(i)
end
end
end
end
end)
Any reason you are checking TeamColor instead of Team.Name? Since TeamColor is a BrickColor, I would not suggest you check it against a string. Instead, I would just check Team.Name == “French” or whatever the team name is. Try printing Player.Team.Name and see where that gets you. I am not sure why the TeamColor would not change, unless there was something wrong with the team change code.
This worked great. I adjusted accordingly and it checks Team.Name, and it changes the flag’s decal. Only problem is that it still prints the wrong team name and it seems to only work the first time. (ex. I’ll be on the British team and touch it, I’ll change to the British Flag. I then (in studio) change the team to French and it won’t change back. Updated code below.
--[[ @mocha______ // @MochaTheDev ]]
local britcolor = "British" -- Name for the British team
local frcolor = "French" -- Name for the French team
local frflag = 136161583 -- Asset ID for the French flag decal (e.g., asset://1001391838 or the URL for the decal)
local brflag = 8583156400 -- Asset ID for the British flag decal (e.g., asset://1001391838 or the URL for the decal)
local Players = game:GetService("Players")
local flagmodel = script.Parent.Flag
local flagparts = {flagmodel.a, flagmodel.b, flagmodel.c, flagmodel.d, flagmodel.e, flagmodel.f, flagmodel.g, flagmodel.h, flagmodel.i, flagmodel.j, flagmodel.k, flagmodel.l, flagmodel.m, flagmodel.n, flagmodel.o, flagmodel.p}
script.Parent.base.Touched:Connect(function(touched)
if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
local Player = Players:GetPlayerFromCharacter(touched.Parent)
if Player then
print("Flag Touched by", Player.Team)
if Player.Team.Name == britcolor then
for i, v in pairs(flagparts) do
v.TextureID = "http://www.roblox.com/asset/?id="..brflag
print(i)
end
elseif Player.Team.Name == frcolor then
for i, v in pairs(flagparts) do
v.TextureID = "http://www.roblox.com/asset/?id="..frflag
print(i)
end
end
end
end
end)
Are you changing your team on Client? That would explain it. Press the Currrent: Client to switch to the Server, then switch your team, switch back to Client, then see.
This worked to change the team except my damn studio keeps opening debugger on line 17 for some reason where it does if Player.Team.Name == britcolor then for some reason.
Edit: Fixed it. The script works! Thanks so much. Very tired, many obvious mistakes.