Cannot give data to multiple players

In the script I give some folders to the player that joins. It works, but for some reason when another player joins they get no folders, and they can play for the other player.

In other words: Only 1 person gets folders, and every other player that joins just plays for the 1st player.

game.Players.PlayerAdded:Connect(function(plr)
	
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	
	local vals = Instance.new("Folder", plr)
	vals.Name = "vals"
	
	local reqs = Instance.new("Folder", plr)
	reqs.Name = "reqs"
	
	local givs = Instance.new("Folder", plr)
	givs.Name = "givs"
	
	local giv1 = Instance.new("IntValue", givs)
	giv1.Name = "giv1"
	giv1.Value = 0
	
	local giv2 = Instance.new("IntValue", givs)
	giv2.Name = "giv2"
	giv2.Value = 0
	
	local giv3 = Instance.new("IntValue", givs)
	giv3.Name = "giv3"
	giv3.Value = 0
	
	local giv1B = Instance.new("IntValue", givs)
	giv1B.Name = "giv1B"
	giv1B.Value = 0
	
	local req1 = Instance.new("IntValue", reqs)
	req1.Name = "req1"
	req1.Value = 0
	
	local req2 = Instance.new("IntValue", reqs)
	req2.Name = "req2"
	req2.Value = 0
	
	local req3 = Instance.new("IntValue", reqs)
	req3.Name = "req3"
	req3.Value = 0
	
	local req1B = Instance.new("IntValue", reqs)
	req1B.Name = "req1B"
	req1B.Value = 0
	
	local spcVals = Instance.new("Folder", plr)
	spcVals.Name = "spcVals"
	
	local soulwait = Instance.new("IntValue", spcVals)
	soulwait.Name = "SOULWAIT"
	soulwait.Value = 1
	
	local soul = Instance.new("IntValue", leaderstats)
	soul.Name = "Soul"
	soul.Value = 100000
	
	local dirt = Instance.new("IntValue", vals)
	dirt.Name = "Dirt"
	dirt.Value = 0
	
	local grass = Instance.new("IntValue", vals)
	grass.Name = "Grass"
	grass.Value = 2000
	
	local stone = Instance.new("IntValue", vals)
	stone.Name = "Stone"
	stone.Value = 500

end)
1 Like

Is this run server-sided or client-sided?

1 Like

Make sure this is done in ServerScriptService.

1 Like

Try this.

function addData(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	local soul = Instance.new("IntValue", leaderstats)
	soul.Name = "Soul"
	soul.Value = 100000
	
	local vals = Instance.new("Folder", plr)
	vals.Name = "vals"
	local dirt = Instance.new("IntValue", vals)
	dirt.Name = "Dirt"
	dirt.Value = 0
	local grass = Instance.new("IntValue", vals)
	grass.Name = "Grass"
	grass.Value = 2000
	local stone = Instance.new("IntValue", vals)
	stone.Name = "Stone"
	stone.Value = 500
	
	local reqs = Instance.new("Folder", plr)
	reqs.Name = "reqs"
	local req1 = Instance.new("IntValue", reqs)
	req1.Name = "req1"
	req1.Value = 0
	local req2 = Instance.new("IntValue", reqs)
	req2.Name = "req2"
	req2.Value = 0
	local req3 = Instance.new("IntValue", reqs)
	req3.Name = "req3"
	req3.Value = 0
	local req1B = Instance.new("IntValue", reqs)
	req1B.Name = "req1B"
	req1B.Value = 0
	
	local givs = Instance.new("Folder", plr)
	givs.Name = "givs"
	local giv1 = Instance.new("IntValue", givs)
	giv1.Name = "giv1"
	giv1.Value = 0
	local giv2 = Instance.new("IntValue", givs)
	giv2.Name = "giv2"
	giv2.Value = 0
	local giv3 = Instance.new("IntValue", givs)
	giv3.Name = "giv3"
	giv3.Value = 0
	local giv1B = Instance.new("IntValue", givs)
	giv1B.Name = "giv1B"
	giv1B.Value = 0
	
	local spcVals = Instance.new("Folder", plr)
	spcVals.Name = "spcVals"
	local soulwait = Instance.new("IntValue", spcVals)
	soulwait.Name = "SOULWAIT"
	soulwait.Value = 1
end


game.Players.PlayerAdded:Connect(addData)
1 Like

Same problem happens. The second player has 100k soul permanently and plays for the other player.

1 Like

server sided in serverscriptservice

1 Like

This should work, I have a script like this and it works. try this script and check the output.

game.Players.PlayerAdded:Connect(function(plr)
	print(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	
	local vals = Instance.new("Folder", plr)
	vals.Name = "vals"
	
	local reqs = Instance.new("Folder", plr)
	reqs.Name = "reqs"
	
	local givs = Instance.new("Folder", plr)
	givs.Name = "givs"
	
	local giv1 = Instance.new("IntValue", givs)
	giv1.Name = "giv1"
	giv1.Value = 0
	
	local giv2 = Instance.new("IntValue", givs)
	giv2.Name = "giv2"
	giv2.Value = 0
	
	local giv3 = Instance.new("IntValue", givs)
	giv3.Name = "giv3"
	giv3.Value = 0
	
	local giv1B = Instance.new("IntValue", givs)
	giv1B.Name = "giv1B"
	giv1B.Value = 0
	
	local req1 = Instance.new("IntValue", reqs)
	req1.Name = "req1"
	req1.Value = 0
	
	local req2 = Instance.new("IntValue", reqs)
	req2.Name = "req2"
	req2.Value = 0
	
	local req3 = Instance.new("IntValue", reqs)
	req3.Name = "req3"
	req3.Value = 0
	
	local req1B = Instance.new("IntValue", reqs)
	req1B.Name = "req1B"
	req1B.Value = 0
	
	local spcVals = Instance.new("Folder", plr)
	spcVals.Name = "spcVals"
	
	local soulwait = Instance.new("IntValue", spcVals)
	soulwait.Name = "SOULWAIT"
	soulwait.Value = 1
	
	local soul = Instance.new("IntValue", leaderstats)
	soul.Name = "Soul"
	soul.Value = 100000
	
	local dirt = Instance.new("IntValue", vals)
	dirt.Name = "Dirt"
	dirt.Value = 0
	
	local grass = Instance.new("IntValue", vals)
	grass.Name = "Grass"
	grass.Value = 2000
	
	local stone = Instance.new("IntValue", vals)
	stone.Name = "Stone"
	stone.Value = 500

end)

I just noticed that it’s actually not because the player doesn’t get the stats.
Rather the problem is that the local scripts trigger for the other player.
But the leaderstats aren’t server sided, so why the other local scripts are I don’t know?

So basically you’re saying that when a player joins, this function does not run at all. Also check if the leader stats gets disabled after the first player.

Nono. It always worked. The actual problem is that the localscripts trigger on every player that has joined. For example if I do something that triggers a sound in a localscript, then the other player will hear that sound too.

So, i made this script, might help with what you are doing?


local Folders = {"leaderstats", "vals", "reqs", "givs", "spcVals"} -- Array of Folders

function CreateList(Location: Instance?, List: {}, Type: string?)
	for item, val in List do -- Iterates through an Array
		if typeof(item) == "number" then -- this is an extra measure to check if the name is not a number (DO NOT REMOVE)
			local New = Instance.new(Type) -- Applys Values.
			New.Name = val -- Changes name to val as the Normal Name is a number
			New.Parent = Location -- Parents New Value
			print("Created:", val) -- Debugging
		else
			local New = Instance.new(Type) -- Applys Values...
			New.Name = item -- Changes name to the Orginal name
			New.Parent = Location -- Parents New Value
			print("Created:", item) -- Also Debugging
		end
	end
end


CreateList(workspace, Folders, "Folder") -- Fires Code
2 Likes

You sure you know the differences between localscript and serverscript symbol??

What do you mean?
image
these should all be localscripts to my knowledge

this is very helpful for time save ty

Other players cant hear the sound if its triggered in a local script. Something is wrong with your Roblox Studio

That’s an absurd amount of LocalScripts

My Studio? I am testing it in the actual roblox game.

Then how is the sound playing for other players in a local script?

I don’t know. Here is the section in the script:
image
My only guess is that the function needs a localplayer variable, but how would the 2nd player touching trigger it in on the server anyway?

Do your other ServerScripts work in serverscriptservice?