Raycast detecting part after disappeared

  1. 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

  2. What is the issue?
    After choice2 detects enemy, if enemy is moved or even deleted it still detects enemy

  3. 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)

your moving the part on the client.

to the server, that enemy part is still in the same position!

click this button to change to the server:
IMG_8999

then your changes to the enemy will be noticed.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.