I've managed to make a script that makes a text label visible when it hovers over a model. My question is, how do I; A) Make a table so it works on multiple models B) Make the gui be displayed only at a distance no larger than 16.
Thanks in advance.
Here's the code:
01 | local RunService = game:GetService( "RunService" ) |
02 | local Player = game:GetService( "Players" ).LocalPlayer |
03 | local Mouse = Player:GetMouse() |
04 |
05 | local ActiveParts = workspace:WaitForChild( "Door1" ) |
06 |
07 | local Tag = script.Parent |
08 | Tag.Text = "CLICK TO OPEN" |
09 |
10 |
11 | RunService.RenderStepped:connect( function () |
12 | local Target = Mouse.Target -- Get the object the mouse is hovering over |
13 | if Target and ActiveParts:IsAncestorOf(Target) then -- Check if the part is anywhere inside the model |
14 |
15 |
A) After you make the table, you iterate through it using a generic for
loop. Compare the mouse's target with values in the table.
B) Compare the magnitude of the difference in positions between the mouse's target and your character.
Mouse.Move
event, rather than firing every frame :)01 | local RunService = game:GetService( "RunService" ) |
02 | local Player = game.Players.LocalPlayer |
03 | local Mouse = Player:GetMouse() |
04 | local ActiveParts = { "Door1" , "Door2" } --These are what activate the ui |
05 | local Tag = script.Parent |
06 | Tag.Text = "CLICK TO OPEN" |
07 |
08 | repeat wait() until plr.Character |
09 |
10 | local char = Player.Character |
11 | local root = char:WaitForChild( "HumanoidRootPart" ) |
12 | local minimunDist = 16 --Minumun distance to activate ui |
13 |
14 | Mouse.Move:Connect( function () |
15 | local Target = Mouse.Target |
This script works but it only has one problem, the range won't chance as you move. If you can fix that you will be good to go.
This is how you should place stuff:
StarterGui - Imgur
Workspace - Imgur
This is the VariableHandler:
01 | --[[ |
02 | This script won't work if players decide to be R15 or not |
03 | --]] |
04 |
05 | local player = game:GetService( "Players" ).LocalPlayer |
06 | local char = player.Character |
07 | local torso = char.Torso -- change char.Torso to char.UpperTorso if the game is R15 |
08 | local ActiveParts = workspace:WaitForChild( "Door1" ) |
09 | local WALL = ActiveParts.wall |
10 | _G.WALLrange = (torso.Position - WALL.Position).magnitude |
and this is the TextHandler:
01 | local RunService = game:GetService( "RunService" ) |
02 |
03 | local player = game:GetService( "Players" ).LocalPlayer |
04 | local char = player.Character |
05 | local torso = char.Torso |
06 | local hum = char.Humanoid |
07 | local mouse = player:GetMouse() |
08 |
09 | local ActiveParts = workspace:WaitForChild( "Door1" ) |
10 |
11 | local interface_magnitude = 6.5 |
12 |
13 | local Tag = script.Parent |
14 | Tag.Text = "CLICK TO OPEN" |
15 |