Can somebody help me with this child issue?

Hello, I am trying to access a player leaderstat but for some reason it isn’t going into children. Here is my script and output:

game:GetService("ReplicatedStorage").plusPart.OnServerEvent:Connect(function(player, multiplier)
	player:WaitForChild("leaderstats"):WaitForChild("Parts").Value += multiplier.Value --Value I want to access
end)
  09:58:39.465  Value is not a valid member of Player "Players.Chickennuggetmanwow"  -  Server - Stats:33

What does the call to the ServerEvent look like on the LocalScript? Could be an error on that side.

1 Like

Here:

wait(1)

local player = game.Players.LocalPlayer

local ReplicatedStorage = game:GetService("ReplicatedStorage")

workspace.SpawnPart.Button.ClickDetector.createPart.OnClientEvent:Connect(function()
	for i, v in pairs(ReplicatedStorage:GetChildren()) do
		if v.Name == player.leaderstats.Color.Value then 
			part = v:Clone()
			break
		end
	end
	local multiplier = part:WaitForChild("PartMultiplier").Value
	game:GetService("ReplicatedStorage").plusPart:FireServer(player, multiplier)
	part.Owner.Value = player.Name
	part.Parent = workspace
	part.Position = Vector3.new(math.random(-21, 23.5), 17, math.random(-41.25, -24))
	wait(2)
	part:Destroy()
--      CreatePart()
end)

As suspected, that’s your problem, leave out the player

game:GetService("ReplicatedStorage").plusPart:FireServer(multiplier)

Also the part has an Int in it.

Well, I need to put in the player since the server needs to know which player to fire. I need to increase a leaderstat when it fires.

The player is sent automatically with the call.

+= is not a lua operator. You must do

Parts.Value = Parts.Value + multiplier.Value


and ‘Parts’ and ‘multiplier’ must be a intvalue/numbervalue object or a number

Well it is still saying “attempted to index nil with value”, also I am putting the player in the function first if that does anything.

Server = game:GetService("ReplicatedStorage").plusPart:OnServerEvent(player, multiplier)
Client = game:GetService("ReplicatedStorage").plusPart:FireServer(multiplier)

Keep the player in the server side one but remove it from the client side one.

I am doing that already.
Here are my script changes:

local DataStoreService = game:GetService("DataStoreService")

local PartsStore = DataStoreService:GetDataStore("playerPartsSave")

--Create Leaderstats
game:GetService("Players").PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player) --Leaderstats
	leaderstats.Name = "leaderstats"

	local Parts = Instance.new("IntValue", leaderstats) --Parts
	Parts.Name = "Parts"
	
	local PartColor = Instance.new("StringValue", leaderstats) --PartColor
	PartColor.Name = "Color"
	PartColor.Value = "WhitePart"
	
--Load Data
	local playerUserID = ("Player_" ..  player.UserId)
	
	local success, errorMessage = pcall(function()
		data = PartsStore:GetAsync(playerUserID)
	end)
	if success then
		print("Player Data Loaded")
		Parts.Value = data
		print(data)
	else
		print("Player's data wen't no")
	end
end)
--Add Parts RemoteEvent
game:GetService("ReplicatedStorage").plusPart.OnServerEvent:Connect(function(player, multiplier)
	player:WaitForChild("leaderstats"):WaitForChild("Parts").Value += multiplier.Value
end)
--Save Data
game.Players.PlayerRemoving:Connect(function(player)
	local playerUserID = ("Player_" .. player.UserId)

    local data = player.leaderstats.Parts.Value

	local success, errorMessage = pcall(function()
		PartsStore:SetAsync(playerUserID, player.leaderstats.Parts.Value) 
	end)
	if success then
		print("Data Saved")
	else
		print("Data Fricked Up")
	end
end)

Also, just noticed this, so no need to use multiplier.Value in the server side just use multiplier

I missed that. That fixed it. Sorry.

1 Like

See my last post above. Remove .Value from +=multiplier.Value to +=multiplier

I did. That fixed it.


+= is a lua operator

local i = 1
i = i + 1
--works

i += 1
--also works

I couldn’t really find it anywhere. Sorry.

Exclusive to Luau, compound operators aren’t native to Lua.