Hey Robloxians!
I made a script that kills the player if their highlight doesn’t match the color of the part they touch, but it doesn’t work. It kills the player anyway.
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
for Key, Descendant in pairs(Character:GetDescendants()) do
if Descendant:IsA("BasePart") then
Descendant.Touched:Connect(function(Part)
if Part.Name == "Obstacle" and Part.Color ~= Color3.new(0, 0, 0) and Part.Color ~= Character.Highlight.FillColor then
Character.Humanoid.Health = 0
elseif Part.Name == "Checkpoint" then
Player.RespawnLocation = Part:FindFirstChildOfClass("BasePart")
end
end)
end
end
end)
end)
Any help would be appreciated!
Kind regards, iamajust
You are supposed to be able to stand on black parts with any highlight color. It uses ‘and’ so it only kills you if the part color isn’t black AND your highlight color is not matching the part color.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Highlight = Instance.new("Highlight")
Highlight.FillColor = Color3.fromRGB(160, 160, 160)
Highlight.Parent = Character
local Humanoid = Character:WaitForChild("Humanoid")
if Humanoid then
for _, Descendant in pairs(Character:GetDescendants()) do
if Descendant and Descendant:IsA("BasePart") then
Descendant.Touched:Connect(function(BasePart)
if BasePart and BasePart:IsA("BasePart") and BasePart.Color ~= Highlight.FillColor then
Humanoid.Health = 0
end
end)
end
end
end
end)
end)
Check if Character.Highlight.FillColor is being updated correctly. Print its value and Part.Color to see if they match when the player touches the part.
Yes, your script is already checking if the part’s name is “Obstacle” and if its color is not black. If either of these conditions is true, the player’s health is set to 0. You could try adding print statements to see if these conditions are being met when the player touches the part.