I’m trying to make a script that makes its part appear whenever another specifically named part is touching it. If the new part is named “RadiusF1”, the part should appear and stay that way until “RadiusF1” is no longer touching it. It seems like a pretty simple concept, and while the code does work sometimes, it decides to stop working randomly, usually when the parts aren’t moving anymore.
local TweenService = game:GetService("TweenService")
local function tweenTransparency(part, targetTransparency, duration)
local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tween = TweenService:Create(part, tweenInfo, { Transparency = targetTransparency })
tween:Play()
return tween
end
local function onTouch(otherPart)
if otherPart.Name == "RadiusF1" then
tweenTransparency(script.Parent, 0, 0.5)
script.Parent.CanCollide = true
script.Parent:FindFirstChild("Effects"):FindFirstChild("Specks").Enabled = true
end
end
local function onTouchEnded(otherPart)
tweenTransparency(script.Parent, 1, 0.5)
script.Parent.CanCollide = false
script.Parent:FindFirstChild("Effects"):FindFirstChild("Specks").Enabled = false
end
script.Parent.Touched:Connect(onTouch)
script.Parent.TouchEnded:Connect(onTouchEnded)
“RadiusF1” is a large part attached to a flashlight tool the player can hold. This part is welded to the tool to follow the light. What’s wrong with this code?
Welcome to roblox!
.Touched is really really unreliable, like really.
Take for instance if you’ve ever played an obby that uses it, oh boy you can just jump on kill bricks and nothing will happen.
I’m not aware of any other method. What I wanted to do was have an invisible brick system where the bricks are collidable and visible only if a player holding a light is near them. My approach to this was having this big part around the light and detecting collisions that way, toggling the brick’s visible and collidable state