I am not good in explanation but how do I change the part of the color to red when the part detects a player and turns green when it doesn’t detect a player?
I would appreciate if u could help me with this
local CirclePart = game.Workspace.CirclePart:GetChildren()
local PartChange = game.Workspace.PartChange
local SqaurePart = game.Workspace.SqaurePart:GetChildren()
local SecondPlr = game.Workspace.SecondPlr
PartChange.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
for _,A in pairs(CirclePart) do
A.Transparency = 0
A.CanCollide = true
PartChange.BrickColor = BrickColor.new("Really red")
PartChange.Transparency = 0
print("Part Change really red!")
PartChange.TouchEnded:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
PartChange.BrickColor = BrickColor.new("Lime green")
PartChange.Transparency = .5
A.Transparency = .5
A.CanCollide = false
end
end)
end
end
end)
I don’t really understand your question? Could you provide code.
Otherwise:
Tween service or use a debounce
here you go…
local CirclePart = game.Workspace.CirclePart:GetChildren()
local PartChange = game.Workspace.PartChange
local SqaurePart = game.Workspace.SqaurePart:GetChildren()
local SecondPlr = game.Workspace.SecondPlr
PartChange.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
for _,A in pairs(CirclePart) do
A.Transparency = 0
A.CanCollide = true
PartChange.BrickColor = BrickColor.new("Really red")
PartChange.Transparency = 0
print("Part Change really red!")
PartChange.TouchEnded:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
PartChange.BrickColor = BrickColor.new("Lime green")
PartChange.Transparency = .5
A.Transparency = .5
A.CanCollide = false
end
end)
end
end
end)
My internet died I hope I haven’t missed much
Don’t use TouchEnded
please, it’s extremely unreliable & can work on a lot of wonky effects
One potential option you could try is using Region3
, which takes a specific Region inside a world area & you can detect if the Player is inside that Region or not
local CirclePart = game.Workspace.CirclePart:GetChildren()
local PartChange = game.Workspace.PartChange
local SqaurePart = game.Workspace.SqaurePart:GetChildren()
local SecondPlr = game.Workspace.SecondPlr
local MinSize = PartChange.Position - (PartChange.Size * 0.55)
local MaxSize = PartChange.Position + (PartChange.Size * 0.55)
local Region = Region3.new(MinSize, MaxSize)
while true do
local Parts = workspace:FindPartsInRegion3(Region, PartChange, math.huge)
for _, Part in pairs(Parts) do
local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if Player then
for _, A in pairs(CirclePart) do
A.Transparency = 0
A.CanCollide = true
PartChange.BrickColor = BrickColor.new("Really red")
PartChange.Transparency = 0
print("Part Change really red!")
end
else
for _, A in pairs(CirclePart) do
A.Transparency = 0.5
A.CanCollide = false
PartChange.BrickColor = BrickColor.new("Lime green")
PartChange.Transparency = 0.5
print("Part Change really red!")
end
end
end
wait()
end
You may have to change the MinSize
& MaxSize
properties a bit in order for the script to fully detect that you’re detecting the part, try again? I edited it a bit
is not changing the color after I stepped on and stepped out of the part
Did you at least try the updated script…?
yes, I tried it but like is not changing the color
…Wait why am I increasing the MinSize
& decreasing the MaxSize
values? Bruh
Ok I edited it 1 last time, if it still doesn’t work I’d recommend adding print statements to check what & what doesn’t work
you can do this really easily. Does it matter than when you stand on it it stays red? because you could just make it so if you touch it it turns red, and then after a while it turns back to green.
1 Like
he wants it: green if not stepped, if stepped change to red until leavep art
1 Like