-
What do you want to achieve?
I want it so when the “Equiped” boolvalue inside of “Hazmat suit” is true, the player won’t take damage, and when it is false, the player will take damage. -
What is the issue?
The issue is that it won’t work no matter what the “Equiped” value is. The player still takes damage when touching the “Rad” part.
Also yes, everything is located correctly including the “Equiped” value and “Hazmat suit.”. Btw the “Hazmat suit” script handles weather the “Equiped” value = true or not.
-
What solutions have you tried so far?
I’ve tried asking ChatGPT multiple times about my issue, but it can’t seem to fix it.
This is the script that I am having issues with:
local Players = game:GetService("Players")
local RadiationZones = workspace:WaitForChild("RadiationZones")
local playersInRadiation = {}
local function startRadiationEffect(player, part)
local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
local level = part:FindFirstChild("Level")
if humanoid and level and level:IsA("NumberValue") then
-- Look for the Hazmat suit dynamically in the character's hierarchy
local character = player.Character
local hazmatSuit = character and character:FindFirstChild("Hazmat suit")
if hazmatSuit then
local equipValue = hazmatSuit:FindFirstChild("Equiped")
if equipValue and equipValue:IsA("BoolValue") then
if not equipValue.Value then
local healthReducer = coroutine.create(function()
while playersInRadiation[player] == part and humanoid.Health > 0 do
humanoid.Health = humanoid.Health - level.Value
wait(1)
end
end)
coroutine.resume(healthReducer)
else
print("TRUE - No damage taken")
return
end
else
print("Equiped BoolValue not found or not a BoolValue in Hazmat suit")
end
else
print("Hazmat suit not found in character")
end
end
end
local function connectTouchEvents(part)
part.Touched:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if player and not playersInRadiation[player] then
playersInRadiation[player] = part
-- Check Hazmat suit when player touches Rad part
local hazmatSuit = character:FindFirstChild("Hazmat suit")
if hazmatSuit then
local equipValue = hazmatSuit:FindFirstChild("Equiped")
if equipValue and equipValue:IsA("BoolValue") then
startRadiationEffect(player, part)
else
print("Equiped BoolValue not found or not a BoolValue in Hazmat suit")
end
else
print("Hazmat suit not found in character")
end
end
end)
part.TouchEnded:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if player and playersInRadiation[player] == part then
playersInRadiation[player] = nil
end
end)
end
-- Function to connect touch events for existing Rad parts
local function connectExistingRadParts()
for _, radPart in pairs(RadiationZones:GetChildren()) do
if radPart:IsA("BasePart") and radPart.Name == "Rad" then
connectTouchEvents(radPart)
end
end
end
-- Connect touch events for existing Rad parts
connectExistingRadParts()
-- Connect new Rad parts added to the RadiationZones folder
RadiationZones.ChildAdded:Connect(function(child)
if child:IsA("BasePart") and child.Name == "Rad" then
connectTouchEvents(child)
end
end)
-- Handle players joining the game
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Wait for the character to fully load
wait(1)
local hazmatSuit = character:FindFirstChild("Hazmat suit")
if hazmatSuit then
connectExistingRadParts()
end
end)
end)
-- Ensure playersInRadiation is updated properly when players leave the game
Players.PlayerRemoving:Connect(function(player)
playersInRadiation[player] = nil
end)
And for context here is the original script without checking the “Equiped” value. (This works fine, but I want it like I explained)
local RadiationZones = game.Workspace:WaitForChild("RadiationZones")
local Players = game:GetService("Players")
-- Table to keep track of players in radiation zones
local playersInRadiation = {}
-- Function to handle touching Rad parts
local function startRadiationEffect(player, part)
local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
local level = part:FindFirstChild("Level")
if humanoid and level and level:IsA("NumberValue") then
local healthReducer = coroutine.create(function()
while playersInRadiation[player] == part and humanoid.Health > 0 do
humanoid.Health = humanoid.Health - level.Value
wait(1)
end
end)
coroutine.resume(healthReducer)
end
end
-- Function to connect touch events
local function connectTouchEvents(part)
part.Touched:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if player and not playersInRadiation[player] then
playersInRadiation[player] = part
startRadiationEffect(player, part)
end
end)
part.TouchEnded:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if player and playersInRadiation[player] == part then
playersInRadiation[player] = nil
end
end)
end
-- Connect touch events for each Rad part
for _, radPart in pairs(RadiationZones:GetChildren()) do
if radPart:IsA("BasePart") and radPart.Name == "Rad" then
connectTouchEvents(radPart)
end
end
-- Connect new Rad parts added to the RadiationZones folder
RadiationZones.ChildAdded:Connect(function(child)
if child:IsA("BasePart") and child.Name == "Rad" then
connectTouchEvents(child)
end
end)
-- Ensure playersInRadiation is updated properly when players leave the game
Players.PlayerRemoving:Connect(function(player)
playersInRadiation[player] = nil
end)
If anyone can help me fix this or point out what I did wrong it would be much appreciated.