Hi my name is Pixeluted and I don’t know how to do if player look at part then fire some function but I don’t know how
Thank for all respond and read
Do you mean that if the player’s cursor is hovering over the part, then something happens? If yes, you could try a ClickDetector.
How ClickDetector Help me say me.
Here’s an example of what I came up with:
script.Parent.ClickDetector.MouseHoverEnter:Connect(function(Player)
Player.Character.Humanoid.Jump = true
end)
script.Parent.ClickDetector.MouseHoverLeave:Connect(function(Player)
Player.Character.Humanoid.Sit = true
end)
If the player’s cursor touches the part, it makes them jump, if the player’s cursor leaves the part, it makes them sit. This is just an example.
Thank but I need how to do then icon don’t be see
What are you trying to make it do?
I want do slender if you look at his face then you kno what happens
So if you look at slender, a GUI shows?
What about:
script.Parent.ClickDetector.MouseHoverEnter:Connect(function(Player)
Player.PlayerGui.ScreenGui.Enabled = true
end)
script.Parent.ClickDetector.MouseHoverLeave:Connect(function(Player)
Player.PlayerGui.ScreenGui.Enabled = false
end)
It looks like you want to be able to tell if something is visible on the player’s screen.
What you could try is using WorldToViewportPoint
in a local script.
workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
local _, visible = cam:WorldToViewportPoint([[slender's position]])
print(visible)
if (visible) then
-- Code that makes the scary blinding effect.
else
-- Turn off the effect since they are no longer looking at him.
end
end)
You can use WorldToScreenPoint to detect if he’s on the screen
and Raycasting to detect if you can’t see him because a wall is behind him.
Example code :
local part = workspace.Part
game:GetService("RunService").Heartbeat:Connect(function()
local a,see = workspace.CurrentCamera:WorldToScreenPoint(part.CFrame.Position)
if see then
local ray = Ray.new(workspace.CurrentCamera.CFrame.Position,(part.CFrame.Position - workspace.CurrentCamera.CFrame.Position))
local Part = workspace:FindPartOnRay(ray,game:GetService("Players").LocalPlayer.Character)
if Part == part then
print("yes you can see it")
else
print("no, you can't see it because something is behind")
end
else
print("not on the screen")
end
end)
yes but the problem with your technique is that if slender is behind a wall it still will count as “seen”, thats why i used raycasting