–Function
What this script does it if you are wear a certain suit on your torso it would deactivated harmful areas and it does work.
–Problem
Except when you join the game while your wearing the suit already. Meaning you have to take it off and the put it on again for the script to work.
Script is found in StarterPlayerScript.
local plr = game.Players.LocalPlayer
local suitType = plr:WaitForChild("ArmorEquipped")
local torso = suitType.Torso
local warnA = game.Workspace.WarningAreaNotif
torso.Changed:Connect(function (newValue)
if typeof(newValue) ~= "Instance" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HazmatAreas" then
p.CanTouch = true
p.damageScript.Enabled = true
end
end
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "ColdSuitAreas" then
p.CanTouch = true
p.damageScript.Enabled = true
end
end
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HeatSuitAreas" then
p.CanTouch = true
p.damageScript.Enabled = true
end
end
else
if newValue.Name == "Basic Top" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HazmatAreas" then
p.CanTouch = false
p.damageScript.Enabled = false
end
end
end
if newValue.Name == "Basic Top" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "ColdSuitAreas" then
p.CanTouch = false
p.damageScript.Enabled = false
end
end
end
if newValue.Name == "Basic Top" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HeatSuitAreas" then
p.CanTouch = false
p.damageScript.Enabled = false
end
end
end
end
end)
Im sure the problem has the do something with the .Changed at the function.
You need to separate the function from the Changed event so you are able to call it when it is first ran
This will call the TorsoUpdated function when that ObjectValue is changed or when the script is first ran which should solve your issue
local plr = game.Players.LocalPlayer
local suitType = plr:WaitForChild("ArmorEquipped")
local torso = suitType.Torso
local warnA = game.Workspace.WarningAreaNotif
local function TorsoUpdated(newValue)
if typeof(newValue) ~= "Instance" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HazmatAreas" then
p.CanTouch = true
p.damageScript.Enabled = true
end
end
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "ColdSuitAreas" then
p.CanTouch = true
p.damageScript.Enabled = true
end
end
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HeatSuitAreas" then
p.CanTouch = true
p.damageScript.Enabled = true
end
end
else
if newValue.Name == "Basic Top" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HazmatAreas" then
p.CanTouch = false
p.damageScript.Enabled = false
end
end
end
if newValue.Name == "Basic Top" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "ColdSuitAreas" then
p.CanTouch = false
p.damageScript.Enabled = false
end
end
end
if newValue.Name == "Basic Top" then
for i, p in pairs(warnA:GetChildren()) do
if p.Name == "HeatSuitAreas" then
p.CanTouch = false
p.damageScript.Enabled = false
end
end
end
end
end
torso.Changed:Connect(TorsoUpdated)
TorsoUpdated(torso.Value)