Hi! I want to create the flashlight effect like in windows 10
This work incorrect
plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
fe = script.parent
while true do
wait(0.1)
fe.Position = Udim2.new(mouse.X, mouse.Y)
end
Hi! I want to create the flashlight effect like in windows 10
This work incorrect
plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
fe = script.parent
while true do
wait(0.1)
fe.Position = Udim2.new(mouse.X, mouse.Y)
end
Udim2.new()
uses four arguments (X.Scale,X.Offset,Y.Scale,Y.Offset)
, so you should use UDim2.fromOffset
that will match your situation or just try Udim2.new(0, mouse.X, 0, mouse.Y)
.
Also, i think you would want it to update every frame, so instead of while loop you can use RunService.RenderStepped
event like:
game:GetService("RunService").RenderStepped:Connect(function()
fe.Position = Udim2.fromOffset(mouse.X, mouse.Y)
end)
Hope this helps!
Actually I would use mouse.Move:Connect as itāll be a lot more performant to update the position only when the player moves the mouse and not every frame. And u donāt get any stuttering either
local players = game:GetService("Players")
local plr = players.LocalPlayer or players.PlayerAdded:Wait()
local mouse = plr:GetMouse()
local fe = script.parent
mouse.Moved:Connect(function()
local mousePos = mouse.Hit.p --gets mouse position as a Vector3 value
local mousePos2 = mouse.Hit -- gets mouse position as a CFrame value
end)
As the previous post suggested make use of the āMovedā event belonging to the mouse instance which is fired every time the mouse is move, Iāve also added 2 different ways in which the cursorās current location can be ascertained. On an added note, you should declare all variables as locals.
Local variables are obtained faster than global variables because theyāre integrated into the environment in which they were created. If possible, you should always use local variables over global variables, unless thereās a specific reason otherwise.