I’ve been trying to script whether a barrier (forcefield) is active or not for each player that enters a game. The script tries to cycle through each forcefield and check against the players saved forcefield data (I really can’t think of another way). All I want it to do is compare the BoolValue.Name against the Forcefield.Name and if true then print(). Later on I can compare the Values of the 2 variables and replace the forcefields BoolValue.Value with the BoolValue saved by the player (if there’s a better way please tell me).
I’ve been getting countless problems as I go through it and change things and I guess I’m not understanding the issue. Here is the script and the error.
---- Testing forcefields dividing each zone (add to player data script when working) ----
game.Players.PlayerAdded:Connect(function(player)
local forcefields = Instance.new("Folder", player)
forcefields.Name = "Forcefields"
local forcefield1 = Instance.new("BoolValue", forcefields)
forcefield1.Name = "Forcefield1"
forcefield1.Value = true
local forcefield2 = Instance.new("BoolValue", forcefields)
forcefield2.Name = "Forcefield2"
forcefield2.Value = true
local forcefield3 = Instance.new("BoolValue", forcefields)
forcefield3.Name = "Forcefield3"
forcefield3.Value = true
local forcefield4 = Instance.new("BoolValue", forcefields)
forcefield4.Name = "Forcefield4"
forcefield4.Value = true
local forcefield5 = Instance.new("BoolValue", forcefields)
forcefield5.Name = "Forcefield5"
forcefield5.Value = true
---- Find the state of each forcefield in the player and game (separating the zones) ----
if player and forcefields then
--print("Player and forcefields exists")
local forcefieldsInGame = game.Workspace.GameAssets.Forcefields:GetChildren()
for _, forceState in forcefieldsInGame do
for _, state in player:FindFirstChild("Forcefields"):FindFirstChildWhichIsA("BoolValue"):GetChildren() do -- Line 33
if forceState.Name == state.Name then
print("Both names are the same") --checking for future value changes (forcefield on/off for each player)
end
end
end
end
end)
--[[
TODO:
Have a saved state in the player data for each forcefield. If bought/notBought then
allow forcefield to be the same state
rebirth would then force the players forcefield.(boolean) to true
What is the mission for the forcefields?
firstly we need to check whether a new player has entered and make all the
forcefields CanCollide = true
Transparency = 0
if not new player then check whether the players forcefields are
on (forcefields CanCollide = true, Transparency = 0)
or off (forcefields CanCollide = false, Transparency = 1)
and then make the forcefields that way.
]]