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)
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
I don’t know. Here is the section in the script:
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?