Hello!
I’m trying to make it so that if a player enters a zone, the CarZone value is On and if it exits the zone, the RegularZone Value will turn on and the CarZone value will turn off.
However, this script does not seem to work and I do not understand why!
Code:
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Jeep" then
hit.Parent.CarZone.Value = true
hit.Parent.RegularZone.Value = false
return
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent == nil then
hit.Parent.CarZone.Value = false
hit.Parent.RegularZone.Value = true
end
end)
You’re making it so that when the hit variable is done touching, you’re checking if the hit variable’s parent is nil, which makes it so that you check if the hit part isn’t a Jeep, causing the CarValue and RegularZome not to change. So you should check if the hit.Parent is a Jeep.
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Jeep" then
hit.Parent.CarZone.Value = true
hit.Parent.RegularZone.Value = false
return
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent.Name ~= "Jeep" then
hit.Parent.CarZone.Value = false
hit.Parent.RegularZone.Value = true
end
end)
We don’t know what is being touched nor not touching it. Your code is seeing that an object stopped touching it but isn’t finding the object correctly. Be sure to check that you are correctly finding the CarZon object.