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

How do I access players in game.Players via server-sided script?

Here is a script that I have that adds a folder directory within players in game.Players. How do I access these values via a server-sided script that can edit those player-specific values? ex: Change the Class.Value of a specific player.

game.Players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder")
	folder.Parent = player
	folder.Name = "Stats"
	--folder.Name = p.Name
	local Team= Instance.new("StringValue", folder)
	Team.Name = "Team"
	Team.Value = "No team"
	local Class = Instance.new("StringValue", folder)
	Class.Name = "Class"
	Class.Value = "No class"
	local Level = Instance.new("IntValue", folder)
	Level.Name = "Level"
	Level.Value = 1
end)

2 answers

Ill show 2 examples. Through a LocalScript:

local plr = game.Players.LocalPlayer
wait(.25) --Wait so stats can be created
local Class = plr.leaderstats.Class --replace leaderstats with Stats
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input,IsTyping)
	if IsTyping then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		Class.Value = "Testing Class" --Whatever you want
	end
end)

Through .Touched:

local debounce = false
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if debounce == false then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local Level = player.leaderstats.Level --Replace leaderstats with Stats btw
			Level.Value += 1
			debounce = true
			wait(1)
			debounce = false
		end
	end
end)

Edit:Forgot he said server-sided please forgive me

You can edit them using Script, located at ServerScriptService.

game.Players:WaitForChild("ChirpPerson").Stats.Class.Value = "Thing"

5 comments

0

Would this change via a localscript reflect globally (seen by other players and the server)?

0

You also can use LocalScript. but it's for advanced coding uses, like game.Players.LocalPlayer.Stats.Class.Value = "Thing"

0

Both will also effect the Server because Player Service is not client

0

This is absolutely wrong. LocalScripts are programs designated to run on the user's device. The Client only has allotted NetworkOwnership over their Avatar, any other modifications made locally will n o t reflect on the Server.

0

How in the world is a LocalScript, let alone the 'LocalPlayer' pointer, considered "advanced" coding?

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