Hi. I followed a random tutorial on YouTube which is for making a objective marker to guide the player with a beam. What I am trying to do is guide the player from the spawnpoint to a dummy which tells them what the game is about. My issue is that it isn’t functioning and the beam doesnt show up when i load the game.
-- local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Beam = script:WaitForChild("Beam"):Clone()
local function CreateBeam(Beam, Attachment0, Part)
local Attachment1 = Part:FindFirstChild("Attachment")
if Attachment1 then
Beam.Attachment0 = Attachment0
Beam.Attachment1 = Attachment1
end
end
game.ReplicatedStorage.ArrowEvent.OnClientEvent:Connect(function(Part, Value)
if Value == true then
local Attachment0 = HumanoidRootPart:FindFirstChild("RootRigAttachment")
CreateBeam(Beam, Attachment0, Part)
Beam.Parent = Character
else
Beam:Remove()
end
end)
Do you receive any errors when you play? And have you checked whether Attachment1 actually exists, maybe using print(Attachment1)? If Attachment1 doesn’t exist at all, the script will skip the entire part that creates the beam.
RemoteEvents can also have problems sending instances, so it could be that when you send Part1 and Part2 to the client, the remote messes it up and it becomes a nil in the localscript.
I tried the script on my computer, and it works perfectly fine for me. I did have to remove the -- in front of where you define the localplayer in your localscript. Did you maybe forget this?
Can you replace your code with this one? I added prints so that you can check if something is missing somewhere, so could you tell me what gets printed when you run the game?
Localscript:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Beam = script:WaitForChild("Beam"):Clone()
local function CreateBeam(Beam, Attachment0, Part)
local Attachment1 = Part:FindFirstChild("Attachment")
print("Attachment1: "..Attachment1)
if Attachment1 then
Beam.Attachment0 = Attachment0
Beam.Attachment1 = Attachment1
end
end
game.ReplicatedStorage.ArrowEvent.OnClientEvent:Connect(function(Part, Value)
print(Part)
print(Value)
if Value == true then
local Attachment0 = HumanoidRootPart:FindFirstChild("RootRigAttachment")
CreateBeam(Beam, Attachment0, Part)
Beam.Parent = Character
else
Beam:Remove()
end
end)
Is it directly in workspace, or in a model or folder? It could be because you arent using WaitForChild() anywhere, which you should to prevent these kind of things. I suggest you use it for the Part1 and Part2, but also for the RemoteEvent for example.
Edit:
I also just noticed that the attachment in Part1 is called “Attachment1”, while you try to get “Attachment” from Part1. That also causes the script to fail, as there wont be an Attachment1, as you are trying to get it by the wrong name.
I’ve got a few points to make as well as a potential fix for your problem.
Key Points
Make sure there are Attachment instances underneath each Part.
Your Player variable is commented out.
The server starts up sooner than the client. Meaning, that if there’s no wait time between the first Beam iteration starting, then the client won’t be there to listen for the signal from ArrowEvent.
This post should be under #help-and-feedback:scripting-support, you can change this by pressing the edit button (pencil icon) and changing the topic’s location.
Code Adjustments
These are primarily just suggestions, so feel free to do with this information as you’d like!
Instead of using the instancing of game.Playersorgame.ReplicatedStorage you should switch to an alternative of game:GetService("Players")andgame:GetService("ReplicatedStorage"). This is because no matter what, it will always grab the service of PlayersorReplicatedStorage, in case names ever get changed. This does not need to apply for game.Workspace, as you can just use the alternative keyword, workspace.
When using a boolean variable (in your case Value on the client) on a conditional statement (in your case if Value == true then), you can remove the == true and just change it to if Value then.
The global function wait() is deprecated, it’s standardized to use task.wait() instead through the task library.