Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help the magnitude is not working it's on line 25, please help?

Help please.

local player = game.Players.LocalPlayer

local character = game.Players.LocalPlayer.Character

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

-- Find NPC

local NPC = game.Workspace.NPC

-- Main Variables

local UIS = game:GetService("UserInputService")

local distance = 15

-- Gui

local GUI = game.StarterGui.NPC_Chat_System

local guiFrame = GUI.NPC_Chat_Frame

-- Main Code

if (humanoidRootPart.Position - NPC.HumanoidRootPart.Position).magnitude < distance then

guiFrame.Visible = true

end

2 comments

0

Can you please elaborate? What are you trying to achieve exactly?

0

I was testing a bit

1 answer

✓ Accepted answer

The issue here is that it won't become visible because you are not updating the distance check. So what I would suggest doing is:

Also the way you are accessing the ScreenGui is not valid. so instead do this:

local player = game.Players.LocalPlayer

local character = game.Players.LocalPlayer.Character

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

-- Find NPC

local NPC = game.Workspace.NPC

-- Main Variables

local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")

local distance = 15

-- Gui

local GUI = player.PlayerGui:WaitForChild("NPC_Chat_System")--getting the gui from the **PlayerGui** *

local guiFrame = GUI.NPC_Chat_Frame

-- Main Code
RS.RenderStepped:connect(function() -- constantly updating the distance check
	if (humanoidRootPart.Position - NPC.HumanoidRootPart.Position).magnitude < distance then
		guiFrame.Visible = true
	else
		guiFrame.Visible = false
	end
end)

8 comments

0

That doesn't work

0

Oh, sorry. From my understanding your script is not making the gui visible whenever their distance is less than 15 units correct?

0

And if there are any output errors please tell us what it is.

0

There are no errors in the output but no gui becoming visible.

0

Where is your local script located? Inside of a ScreenGui?

0

Yes

0

Ok i will edit the answer right now, should work.

0

thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.