Hello,
I’m working on a system where if you face a model with a child of a string value that deems it a point of interest, but a problem that I’ve been running into is that if my take my hand off my mouse and try to walk around, the game seemingly does not pick up the mouse movement at all since my mouse “technically” did not move. Is there a way I could fix that?
I’ve tried RunService:Heartbeat:Wait() mainly, as well as other “if mouse.target ~= currenttarget then” but nothing seems to work. Please if somebody can, let me know if there is something I can even do about this, or if roblox is once again being an impossible platform.
The Code:
local UIS = game:GetService("UserInputService")
local Tween = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = game:GetService('Players').LocalPlayer
local ScreenFade = Player.PlayerGui:WaitForChild("TransitionFade")
local mouse = Player:GetMouse()
local InteractDistance = 15
local currentTarget = nil
local highlight = nil
local function CreateHighlight(target)
local newHighlight = game.ReplicatedStorage:WaitForChild("Selection"):Clone()
newHighlight.Parent = target
return newHighlight
end
mouse.Move:Connect(function()
local target = mouse.Target
if target and target:FindFirstChild("StringValue") and target.StringValue.Value == "Interest" then
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local distance = (humanoidRootPart.Position - target.Position).Magnitude
if distance <= InteractDistance then
if currentTarget ~= target then
if highlight then
highlight:Destroy()
highlight = nil
RunService.Heartbeat:Wait()
end
currentTarget = target
highlight = CreateHighlight(currentTarget)
highlight.FillColor = target:WaitForChild("Rarity").Value
highlight.OutlineColor = target:WaitForChild("Rarity").Value
end
else
if currentTarget then
if highlight then
highlight:Destroy()
highlight = nil
end
currentTarget = nil
end
end
else
if currentTarget then
if highlight then
highlight:Destroy()
highlight = nil
end
currentTarget = nil
end
end
end)
Video example of the issue in motion:
https://i.gyazo.com/9edab03d7d1513c1bf0487119e4621cb.mp4
if anybody has any advice or help they can give me of any kind that’d be amazing, I’m a solo developer so not really the best at anything since I’ve had to multitask everything. Any help means the world.