-
What do you want to achieve?
For the system to let the people teleport to the flag holder. Also, it only works once and if someone else equips it after the first person unequips it it breaks. -
What is the issue?
It only works once and for the first person to hold the flag. Even when the original equipper unequips it, the next person to cannot be teleported to.
robloxapp-20220411-1030331.wmv (4.2 MB) -
What solutions have you tried so far?
I’ve tried adding more values and parameters to make it easier but it only fixed the folder.
local FlagModule = {}
function FlagModule.FlagEquipped(uselesstable, flag, equippedby : Player)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local PlayersService = game:GetService("Players")
local FindFlagValueFolder = ReplicatedStorageService.FlagValues:FindFirstChild(tostring(flag))
local FindFlagEquippedValue
local FindFlagObjectValue
local FindFlagEquippedByObjectValue
if FindFlagValueFolder then
FindFlagEquippedValue = FindFlagValueFolder:FindFirstChild("Equipped")
FindFlagObjectValue = FindFlagValueFolder:FindFirstChild("FlagObject")
FindFlagEquippedByObjectValue = FindFlagValueFolder:FindFirstChild("EquippedBy")
if FindFlagEquippedValue then
FindFlagEquippedValue.Value = true
else
FindFlagEquippedValue = Instance.new("BoolValue", FindFlagValueFolder)
FindFlagEquippedValue.Name = "Equipped"
end
if FindFlagObjectValue then
FindFlagEquippedValue.Value = flag
else
FindFlagEquippedValue = Instance.new("ObjectValue", FindFlagValueFolder)
FindFlagEquippedValue.Name = "FlagObject"
FindFlagEquippedValue.Value = flag
end
if FindFlagEquippedByObjectValue then
if FindFlagEquippedByObjectValue.Value == nil then
FindFlagEquippedByObjectValue.Value = equippedby
FindFlagEquippedValue.Value = true
end
end
else
FindFlagValueFolder = Instance.new("Folder", ReplicatedStorageService.FlagValues)
FindFlagValueFolder.Name = tostring(flag)
if not FindFlagEquippedValue then
FindFlagEquippedValue = Instance.new("BoolValue", FindFlagValueFolder)
FindFlagEquippedValue.Name = "Equipped"
FindFlagEquippedValue.Value = true
end
if not FindFlagObjectValue then
FindFlagEquippedValue = Instance.new("ObjectValue", FindFlagValueFolder)
FindFlagEquippedValue.Name = "FlagObject"
FindFlagEquippedValue.Value = flag
end
if not FindFlagEquippedByObjectValue then
FindFlagEquippedValue = Instance.new("ObjectValue", FindFlagValueFolder)
FindFlagEquippedValue.Name = "EquippedBy"
FindFlagEquippedValue.Value = equippedby
print(equippedby.Parent)
end
end
end
function FlagModule.FlagUnequipped(uselesstable, flag, unequippedby : Player)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local FlagValuesFolder = ReplicatedStorageService:FindFirstChild(tostring(flag), true)
if unequippedby == FlagValuesFolder.EquippedBy.Value then
FlagValuesFolder.Equipped.Value = false
FlagValuesFolder.EquippedBy.Value = nil
end
end
function FlagModule.TeleportToFlag(uselesstable, flagname, player)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local FlagValuesFolder = ReplicatedStorageService:FindFirstChild(tostring(flagname), true)
if FlagValuesFolder then
if FlagValuesFolder.Equipped.Value == true then
player.Character.HumanoidRootPart.CFrame = CFrame.new(FlagValuesFolder.FlagObject.Value.Parent.HumanoidRootPart.CFrame.Position)
end
end
end
return FlagModule