-
What do you want to achieve?
When choice2 sees a part called enemy under it, the transparency goes to 0, otherwise it’s at 0.5 -
What is the issue?
After choice2 detects enemy, if enemy is moved or even deleted it still detects enemy
-
What solutions have you tried so far?
I watched tutorials to make sure I didn’t miss anything and looked at these on dev hub: Raycasting is not detecting other parts
Raycasting is not detecting other parts
How would I detect when a ray leaves a part?
Raycast detecting parts with canquery off
This is the script, it is inside of a group where everything else is. It’s my first time trying out raycasting ever.
local button = game:GetService("Workspace").ChessFunctions:WaitForChild("Button")
local num2 = game:GetService("Workspace").ChessFunctions:WaitForChild("Num2")
local choice1 = game:GetService("Workspace").ChessFunctions:WaitForChild("Choice1")
local choice2 = game:GetService("Workspace").ChessFunctions:WaitForChild("Choice2")
local enemy = game:GetService("Workspace").ChessFunctions:WaitForChild("Enemy")
button.ClickDetector.MouseClick:Connect(function()
local RayOrigin = choice2.Position
local RayDestition = enemy.Position
local RayDirection = choice2.CFrame.LookVector * 50
local ray = Ray.new(RayOrigin, RayDirection)
local part = workspace:FindPartOnRay(ray, script)
print(part)
end)