Ok, so I’ve been struggling with this problem for awhile now. I am trying to destroy a forcefield upon the player joining a specific team. It will not work no matter what I do, except when I add while wait(0.1) do. I remove it and it just does not want to work. Everything in the script working except after the elseif.
Before making this script, I’ve tried countless other ones but it inevitably led to the same answer.
I am asking for someone to fix my code, and tell me what I have been doing wrong, because this problem is completely out of my knowledge of scripting (not much)
Here is my local script inside of player scripts;
while wait(0.1) do
local Teams = game:GetService("Teams")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
repeat wait() until char:FindFirstChild("Humanoid")
local human = char.Humanoid
if player.Team == Teams["Safe"] then
local forcefield = Instance.new("ForceField",char)
elseif char:FindFirstChildWhichIsA("ForceField") then char:FindFirstChildWhichIsA("ForceField"):Destroy()
end
end
while wait() do
local Teams = game:GetService("Teams")
for i,v in pairs(game.Players:GetPlayers()) do
local character = v.Character
if character then
if player.Team == Teams["Safe"] then
local ForceField = Instance.new("ForceField")
ForceField.Parent = character
elseif char:FindFirstChildWhichIsA("ForceField") then
char:FindFirstChildWhichIsA("ForceField"):Destroy()
end
end
end
while wait(0.1) do
local Teams = game:GetService("Teams")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
repeat wait() until char:FindFirstChild("Humanoid")
local human = char.Humanoid
if player.Team == Teams["Safe"] then
local findFF = char:FindFirstChildWhichIsA("ForceField")
if findFF then findFF:Destroy() end
local forcefield = Instance.new("ForceField",char)
elseif char:FindFirstChildWhichIsA("ForceField") then char:FindFirstChildWhichIsA("ForceField"):Destroy()
end
end
while wait(0.1) do
local Teams = game:GetService("Teams")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
repeat wait() until char:FindFirstChild("Humanoid")
local human = char.Humanoid
if player.Team == Teams["Safe"] then
local forcefield = Instance.new("ForceField",char)
else
if char:FindFirstChildWhichIsA("ForceField") then
char:FindFirstChildWhichIsA("ForceField"):Destroy()
end
end
end
Sorry I confused myself put this in a server script
local Team = game.Teams
local Safe = Team:FindFirstChild("Safe")
for i,player in pairs(game.Players:GetChildren()) do
local Character = player.Character
if player.Team == Safe then
if not Character:FindFirstChild("ForceField") then
local Field = Instance.new("ForceField",Character)
end
else
if Character:FindFirstChild("ForceField") then
Character.ForcedField:Destroy()
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if Player.Team == InsertTeamEtc then
Instance.new("ForceField")
else
Character:WaitForChild("ForceField"):Destroy()
end
end)
end)