How to go about making a beam that finds objects for you

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    making a beam show up in my HumanoidRootPart and to an object i want to find
  2. What is the issue?
    i cant find solutions on YouTube
  3. What solutions have you tried so far?
    i tried YouTube but nothing showed up

i making it so that when i spawn in the game it pops up saying “Find Clive to explore the shop”
with the beam i mentioned so that the player knows where to go if “Clive” isn’t anywhere near them

if there is any videos to follow showing this or if you can help please feel free to continue with this Topic

Currently still trying to find a video

What you need to do is put a script inside of starter player scripts with a beam inside of it. Customize the beam to the textures and properties of your liking, and then clone it into the player.

Assuming you have an npc in the workspace named “Clive” this is how it should go:

Local Player = game.Players.LocalPlayer
Local Character = Player.Character or Player.CharacterAdded:wait()
Local HumanoidRoot = Character:FindFirstChild(“HumanoidRootPart”)
Local Beam = script.Beam
Local Target = game.Workspace.Clive:FindFirstChild(“HumanoidRootPart”)

Local NewBeam = Beam:Clone()
NewBeam.Parent = game.Workspace
NewBeam.Attachment0 = HumanoidRoot: FindFirstChild(“RootRigAttachment”)
NewBeam.Attachment1 = Target: FindFirstChild(“RootRigAttachment”)

I apologize in advance if this is confusing or involves any typos, if you need further assistance I am happy to help :slightly_smiling_face:

could this work from an event from the server to client for only certain players

What I am assuming you mean by that is telling certain players from the server to go to the destination?

If that is correct, then could i ask you to specify what happens in the game? Does a player touch a part, or is it just when a player joins the game??

so basically when the player joins text comes up saying “Go to Clive to view Shop” then after you press ok the beam shows and when you are close to clive the beam goes away (using magnitude which i might need help with)

Okay… so I don’t see why you would need a server side for this script, mainly because text buttons are usually used with local scripts. You could make something like this inside of StarterPlayerScripts…

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRoot = Character:FindFirstChild("HumanoidRootPart")
local Target = game.Workspace.Clive:FindFirstChild("HumanoidRootPart")

local Button = Player.PlayerGui.ScreenGui.TextButton --This is an example where you have a Gui in StarterGui named "ScreenGui" with a TextButton inside --

local Beam = script.Beam

Button.MouseButton1Click:Connect(function() -- Calls a function when the button is clicked --
    Button.Visible = false -- Sets the Button to invisible after being clicked --
    local NewBeam = Beam:Clone() -- Clones a new beam for the player --
    NewBeam.Parent = game.Workspace -- Sets the parent of the cloned beam to the workspace so it is visible --
    NewBeam.Attachment0 = HumanoidRoot:FindFirstChild("RootRigAttachment")
    NewBeam.Attachment1 = Target:FindFirstChild("RootRigAttachment")

    while wait(1) do
        local DistanceFromBeam = Player:DistanceFromCharacter(Target.Position) -- Gets the distance from Clive's Position --
        if DistanceFromBeam <= 50 then -- if the Distance is less than or equal to 50 studs then... -
            NewBeam.Enabled = false
        end
    end
end)

Let me know if this works, I am not an expert when it comes to getting the distance between two objects. :sweat_smile:

everything works thank you but i had to change

local HumanoidRoot = Character:FindFirstChild("HumanoidRootPart")

to

local HumanoidRoot = Character:WaitForChild("HumanoidRootPart")

Okay, glad I could help :grinning:

Just be aware that WaitForChild can sometimes cause errors in your script; if it doesn’t find the object it is looking for, it may yield the script infinitely.

oh but the script doesnt work if its findfirst tho

Well, if it works, it works :slight_smile:

thank you so much anyway :slight_smile:

2 Likes