I have a textlabel that needs to change text to the name of object in front of players cursor. The script perfectly prints the object that was raycasted but I can't get it to change text on the label.
local label = game.StarterGui.guistuff.WhatYouLookinAt
local runservice = game:GetService("RunService")
local function MouseRaycast()
local mousePos = uis:GetMouseLocation()
local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
local rayResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 20)
return rayResult
end
runservice.RenderStepped:Connect(function()
local result = MouseRaycast()
if result and result.Instance then
local objname = result.Instance.Name
label.Text = objname
end
end)
I believe I made a stupid mistake and I should be executed.

2 comments
@mlgfoxydan I have edited my code check it out.
Thank you!