Due to the lack of information, I did not completely know what you wanted to do here but this should give you some Idea. This is already answered by @Kiriot22 but the OP had asked for my answer.
As mentioned by @Kiriot22, you cannot access PlayerScripts from Server Script. You should instead work Local Scripts on this.
I despise using script.Parent because it does not give the reader a good understanding of your code. Consider changing it to Hierarchy layout. It may not work for you the best but do consider it.
- Insert a
Remote Event in Replicated Storage.
- Call the
Remote Event, "EvaluateValueEvent"
- Insert the
Server Script inside the ClickPart.
- Insert the
Local Script in StarterPlayerScripts
local Workspace = game:GetService("Workspace");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local NonPlayerCharacters = Workspace:FindFirstChild("NPC");
local ClickPart = Workspace:FindFirstChild("ClickPart");
local EvaluateValueEvent = ReplicatedStorage:WaitForChild("EvaluateValueEvent");
local function ChangePlayerValue (Player)
EvaluateValueEvent:FireClient(Player);
print("Fired");
end;
ClickPart.ClickDetector.MouseClick:Connect(ChangePlayerValue);
Explanation
The whole code is pretty straight forward. What we are doing here on the first couple lines is just simply declaring. At the processing section, we are firing the EvaluateValueEvent so that the Local Script is triggered when the ClickPart is pressed.
local Workspace = game:GetService("Workspace");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Player = game:GetService("Players").LocalPlayer;
local NonPlayerCharacter = Workspace:WaitForChild("NPC");
local EvaluateValueEvent = ReplicatedStorage:WaitForChild("EvaluateValueEvent");
local Information;
local Target;
local function ChangePlayerValue ()
Information = Player.PlayerScripts:WaitForChild("Information");
Target = Information:WaitForChild("StringValue");
Target.Value = "I don't know what you want to do here.";
print(Target.Value);
end;
EvaluateValueEvent.OnClientEvent:Connect(ChangePlayerValue);
Explanation
Basically, when the EvaluateValueEvent is fired, this function will be triggered. As before, the first couple lines is just declaring variables. On the Processing Section, I am changing the Target's Value to "I don't know what you want to do here." when the EvaluateValueEvent is fired.
You can play around with the code to get your desired result. I don't quite understand what you want to do on Line 2 of your code. But I am sure you can get your result easily.
Should you have any questions, feel free to comment below.
[Learn More]
1 comment
Mark the question as answered and you will receive reputation points also.