#Script isn't returning position more than once

1 messages · Page 1 of 1 (latest)

merry escarp
#

I'm trying to write a script that simulates Mouse.hit.Position with a gui, and while I can get the result atleast once, it seems to only update the position that one time and won't get the position again


local camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character
local HRP = Character.HumanoidRootPart

local Mouse = Player:GetMouse()

HRP:WaitForChild("PseudoMouseLayout")

local PML = HRP.PseudoMouseLayout

PML:WaitForChild("PseudoCursor")

local PseudoCursor = PML.PseudoCursor

local function Get3DPosition()
    local absolutePosition = PseudoCursor.AbsolutePosition

    local unitRay = camera:ScreenPointToRay(absolutePosition.X, absolutePosition.Y)
    local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 100)
    
    return raycastResult.Position
    
end

repeat
print(Get3DPosition())
--print(Mouse.hit.Position)
task.wait(.2)
until
2 == 4```
pure bramble
#

so it updates with teh screen coords

merry escarp
#

wdym

#

like put the script there?

pure bramble
#

ur guis position is not changing

merry escarp
#

well I mean it should be changing

pure bramble
#

its parented to the root part

merry escarp
#

because the gui is a billboard attached to the player

pure bramble
#

its abs pos shouldn't be changing

#

put it under player gui

#

or something

#

it will update with teh screencoords

merry escarp
#

put the script under player gui?

pure bramble
#

the gui cursor

merry escarp
#

if I run the script normally, the position does change

#

but once I try to have it repeat the changing values it doesn't work

pure bramble
#

bc abs value wont change ,its only once

merry escarp
#

the gui HAS to be attached to the character root, because the gui has to be tied to the position of the character

pure bramble
merry escarp
#

So, when you run Mouse.Hit.Position

#

you get a constantly changing value

#

i tried following this post

#

I have a frame inside a billboard gui

#

I need it to return a value like Mouse.Hit.Position does, because i'm trying to make a script where the player always faces the Gui element, because I cannot use hte real cursor

#

The goal is to get the player to always face the gui element

patent orbit
#

that is easy... just make your humanoid rootpart face where the mouse hit . and always update it with run service.

#

RunService.RenderStepped:Connect(function()
local rootPos, MousePos = HRP.Position, Mouse.Hit.Position
HRP.CFrame = CFrame.new(rootPos, Vector3.new(MousePos.X, rootPos.Y, MousePos.Z))
end)

#

with that your humanoid root part will face where your mouse hits .

patent orbit
patent orbit
#

why not

#

it works

#

you only need the player then then get the mouse of the player then if the mouse hit something like baseplate.. the rootpart should face where it hits 🙂

merry escarp
fathom vectorBOT
#

studio** You are now Level 4! **studio