The problem is that I’m trying to make CanCollide true on a part when it’s transparency reaches 0 but for some reason the script is returning a weird number value that I never intended to reach and because of that I can’t make it turn CanCollide on, here’s the script that I’m using:
Script
local part = script.Parent
local TouchedCooldown = false
part.Touched:Connect(function(hit)
local Character = hit.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if Humanoid and not TouchedCooldown then
TouchedCooldown = true
for i = 0,1,0.1 do
part.Transparency = i
wait()
end
print(part.Transparency)
if part.Transparency == 1 then
part.CanCollide = false
print("can collide is false")
end
print("moving on")
wait(0.5)
for i = 1,0,-0.1 do
part.Transparency = i
wait()
end
print(part.Transparency)
if part.Transparency == 0 then
part.CanCollide = true
print("cancollide is on")
end
print("yes")
wait(0.5)
TouchedCooldown = false
end
end)
Because of the debugging that I did I was able to see the reason as to why it’s not turning CanCollide on and it’s because of the weird number value which I never intended to reach like I said above, here’s a picture of my output so you can see what prints in the script, what doesn’t and what’s happening:
Now as you can see when I printed the part.Transparency number value after it’s 0 for some reason it’s not printing 0 instead it prints this weird HUGE number value that I never intended to reach and the Part’s Transparency is 0 after the numeric loop is done and not the weird number value so what’s happening here and how do I fix this?
Is this the number floating point error issue within Roblox Lua or something?