How can I work around this problem?

Hey Roblox devs. I’m trying to make an objective system in my game with arrows and gui. I copied the part with the arrows from a tutorial. The tutorial uses a remote event for the arrows. Here is the script.

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 Attachment 1 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

the problem is, if I wanted to fire the remote event I would have to do it through a server script. But, if I use a server script then I can’t access the local player, which I want to do. But at the same time, I can’t fire an event through the local script. This is what I’m trying to do with the local player:

while true do
	local GeneralMurphy = game.Workspace.NPCs["General Murphy"].HumanoidRootPart
	local GunCrates = game.Workspace["Millitary Plane"].Crates["Military Crates"].ak47gmod

	if player.CurrentObjective.Value == "•Talk to General Murphy" then
		ArrowEvent:FireAllClients(GeneralMurphy, true)	
		ArrowEvent:FireAllClients(GunCrates, false)

	elseif player.CurrentObjective.Value == "•Choose Weapons" then
		ArrowEvent:FireAllClients(GunCrates, true)
		ArrowEvent:FireAllClients(GeneralMurphy, false)

	end	
end

The current objective value is a string value that gets instanced into the player when they join. I want the Arrows to change when that value is equal to a certain thing, but I can’t access that value through a server script because I can’t use local player.

If anybody knows a workaround for this, please let me know…I’m honestly stuck, mainly because the tutorial I watched just showed you what to do, and didn’t explain what everything was in full detail. Here is the video just in case you might need it.

You can’t get the localplayer from serverscript

but you can get the player in the serverscript with many ways like

Here is quick script when a player joins the game detects it:

game.Players.PlayerAdded:Connect(function(plr)
print(plr.Name.." Joined the game!")
-- otherstuff like RemoteEvent:FireClient(plr) or whatever 
end)

Also to detect player spawned character:

game.Players.PlayerAdded:Connect(function(plr)
     plr.CharacterAdded:Connect(function(char)
         print(plr.Name.."'s character added")
     end)
end)

I don’t think you understand…I know I could use a playeradded function but that would only recognize the player as soon as they join. The script that I’m using is getting used throughout the game, so I would need a method that can access the player at any time. The best way I can think of solving my problem is by somehow changing “CurrentObjective” in every player at once, but I wouldn’t know how to do that. Read my scripts, and try figuring out what I’m trying to exactly. I might find out a way to use the playeradded, but if it doesn’t work then I would appreciate it if you can find another solution for me.

Could you re-explain your problem? I am confused on what your problem is

There is a string value, name “CurrentObjective” that every player spawns with. I want to access that variable with a server script, but I can’t because I can’t access “LocalPlayer” in a server script. That’s the main thing, if you want more detail just re read the first post I made. I’m trying to use the playerAdded function and store the player in a variable, but so far it’s not working.

Also, I want to make it so the arrows point to the object that refers to the current objective of a player. Another solution I thought of was going into each and every individual player and changing the variable from there but I have no idea how to do that.

Try this Note: if u changing currentobjective value with serverscript this should works!

Server Script:

local GeneralMurphy = game.Workspace.NPCs:WaitForChild("General Murphy"):WaitForChild("HumanoidRootPart")
local GunCrates = game.Workspace:WaitForChild("Millitary Plane").Crates["Military Crates"].ak47gmod

game.Players.PlayerAdded:Connect(function(player)

    player.CurrentObjective.Changed:Connect(function()
        if player.CurrentObjective.Value == "•Talk to General Murphy" then
		ArrowEvent:FireClient(player,GeneralMurphy, true)	
		ArrowEvent:FireClient(player,GunCrates, false)

	elseif player.CurrentObjective.Value == "•Choose Weapons" then
		ArrowEvent:FireClient(player,GunCrates, true)
		ArrowEvent:FireClient(player,GeneralMurphy, false)

	end	
    end)
end)

Also you have error in your script

if Attachment 1 then -- (Error)

if Attachment1 then -- (Fixed)
local function CreateBeam(Beam, Attachment0, Part)
	local Attachment1 = Part:FindFirstChild("Attachment")
	
	if Attachment 1 then
		Beam.Attachment0 = Attachment0
		Beam.Attachment1 = Attachment1
	end
end

Iterate over each player?
https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayers