(Sorry for the very vague title I wasn’t quite sure how to explain what was going on)
I currently have a module script that updates the players’ team and attributes like health and some items in their backpack. Initially, everything is fine but when I try to flip flop between teams I’m experiencing issues, here are some gifs that better show what the issue is:
case 1: https://gyazo.com/a617477844e5263e067377b6744dcb60
case 2: https://gyazo.com/a617477844e5263e067377b6744dcb60
Case 1 is when I first become a civilian which ends up overwriting ghoul code, and case 2 is the opposite.
Here is my main function body from the module script:
function team.update_inv(player, team)
player.CharacterAdded:Connect(function(char)
local backpack = player:FindFirstChild("Backpack")
if team == "ghoul" then
if not backpack:FindFirstChild("Eat") then
print("ran ghoul")
local eat = f_tools:WaitForChild("Eat"):Clone()
eat.Parent = backpack
end
end
if team == "civilian" then
print("ran civ")
if backpack:FindFirstChild("Eat") then
backpack:FindFirstChild("Eat"):Destroy()
end
end
end)
end
function team.set_ghoul(char)
char:SetAttribute("Team", "Ghoul")
char:SetAttribute("MaxHealth", 200)
local player = Players:GetPlayerFromCharacter(char)
player.Team = Teams:FindFirstChild("Ghoul")
player:LoadCharacter()
end
function team.set_civilian(char)
char:SetAttribute("Team", "Civilian")
char:SetAttribute("MaxHealth", 100)
local player = Players:GetPlayerFromCharacter(char)
player.Team = Teams:FindFirstChild("Civilian")
player:LoadCharacter()
end
And here is the serverscript thats running the module:
re_team.OnServerEvent:Connect(function(player, action)
local char = player.Character or player.CharacterAdded:Wait()
if action == "ghoul" then
module_team.update_inv(player, "ghoul")
module_team.set_ghoul(char)
end
if action == "civilian" then
module_team.update_inv(player, "civilian")
module_team.set_civilian(char)
end
end)