Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt it change the ObjectValue Value on roblox player?

For some reason this only works on studio, its meant to change an objectValue Value to the object you clicked

script.Parent.MouseClick:connect(function(playerWhoClicked)
playerWhoClicked.PlayerScripts.Information.Target.Value = script.Parent.Parent.Parent
end)

1 comment

0

Mark the question as answered and you will receive reputation points also.

2 answers

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
-- [Server Script] 

-- Declaration Section 
-- //Game Services 
local Workspace = game:GetService("Workspace");
local ReplicatedStorage = game:GetService("ReplicatedStorage");

-- //Non-Player Character Location
local NonPlayerCharacters = Workspace:FindFirstChild("NPC");
local ClickPart = Workspace:FindFirstChild("ClickPart");

-- //Remote Event 
local EvaluateValueEvent = ReplicatedStorage:WaitForChild("EvaluateValueEvent");

-- Processing Section 
local function ChangePlayerValue (Player)
	EvaluateValueEvent:FireClient(Player); 
	print("Fired");
end;

-- Connecting Section 
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.

-- Declaration Section 
-- //Game Services 
local Workspace = game:GetService("Workspace");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Player = game:GetService("Players").LocalPlayer;

-- //Non-Player Character Location 
local NonPlayerCharacter = Workspace:WaitForChild("NPC");

-- //Remote Event Location 
local EvaluateValueEvent = ReplicatedStorage:WaitForChild("EvaluateValueEvent");

-- //Variables 
local Information;
local Target;

-- Processing Section 
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;

-- Connecting Section 
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]

You're using a server script, while PlayerScripts is a local instance. You need to place the ObjectValue somewhere else.

This discussion is preserved as it was. New answers, comments, and votes are closed.