Leaderboard member, help me with the error

When a car collides with an opponent, it tries to raise the driver’s kill score.
creator creation succeeded, but the actual leaderboard score does not go up.

— Error message
leadersstats are not a valid member of the model “Workspace”.Recruitment 123"
Start stacking
Leaderboard Script in line 'ServerScriptService.22
Stack End - Server


serverscripterservice in

local datastore =game:GetService("DataStoreService") :GetDataStore("PlayerStats")

game.Players.PlayerAdded:Connect(function(player)
	local ls = Instance.new("Folder",player)
	ls.Name = "leaderstats"
	
	local Money = Instance.new("NumberValue",ls)
	Money.Value = 0
	Money.Name = "Money"
	
	local Kill = Instance.new("NumberValue",ls)
	Kill.Value = 0
	Kill.Name = "Kill"
	
	player.CharacterAdded:Connect(function(char)
		
		char.Humanoid.Died:connect(function()
			local creater = char.Humanoid:FindFirstChild("creator")
			if creater then
				local killplr = creater.Value --죽인플레이어 확인
				if killplr then
					killplr.leaderstats.Kill.Value += 1
				end
			end
		end)
	end)
	
	local ownsSportcar = Instance.new("BoolValue", player)
	ownsSportcar.Name  = "ownsSportcar"
	ownsSportcar.Value = false
	

	
	game.ReplicatedStorage.RemoteEvent2.OnServerEvent:Connect(function()
		if player.leaderstats.Money.Value >= 100 then
			player.leaderstats.Money.Value -= 100
			player.ownsSportcar.Value = true
			
		end
		
	end)
	
	local MoneyData
	local ownsSportcarData
	local KillData
	
	--데이터베이스 탐색
	local success, errormessage = pcall(function()
		MoneyData = datastore:GetAsync(player.UserId.."-Money")
		KillData = datastore:GetAsync(player.UserId.."-Kill")
		ownsSportcarData = datastore:GetAsync(player.UserId.."ownsSportcar")
		
	end)
	if success then
		Money.Value = MoneyData
		Kill.Value = KillData
		ownsSportcar.Value = ownsSportcarData
	else
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)     
	datastore:SetAsync(player.UserId.."-Money",player.leaderstats.Money.Value)
	datastore:SetAsync(player.UserId.."-Kill",player.leaderstats.Kill.Value)
	datastore:SetAsync(player.UserId.."-ownsSportcar",player.ownsSportcar.Value)
end)

ServerStorage internal model car script

local Enabled = true


local function TagHumanoid(humanoid, player)
	local creator_tag = Instance.new("ObjectValue")
	local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant
	local PlayerId = occupantHumanoid.Parent

	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = humanoid
	creator_tag.Value = PlayerId
	
end

local function UntagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	local plr = game:GetService("Players")
	if hit.Parent:FindFirstChild("Humanoid") and Enabled then  --부딪힌 상대 데미지 입는양
		Enabled = false
		if script.Hit.Value == false then

			script.Hit.Value = true 

		
			local number1 = math.floor(0.5 * script.Parent.AssemblyLinearVelocity.Magnitude)

			local hum = hit.Parent:FindFirstChild("Humanoid")

			hum.Health = hum.Health - number1
			TagHumanoid(Humanoid, plr)
			
		
			script.Hit.Value = false
			wait(2)
			Enabled = true
			UntagHumanoid(Humanoid)
		end
		
	end

end)



I think I should recognize the workspace player and the game player the same way, but I don’t know what to do. Help me.

check spelling i see its looking for Leadersstats not

local ls = Instance.new("Folder",player)
   ls.Name = "leaderstats"

It was a typo due to a translation error.I fixed it.

1 Like

The error message indicates that there is an issue with the line of code that tries to access the leaderstats property of the player object.

you need to ensure that you are accessing the leaderstats property of the correct object. In this case, you should be accessing it as a member of the player object, which is the object that represents the player in the game.

Looking at your code, it seems that the issue might be in the car script where you are trying to tag the humanoid with the creator object. The creator object is set to the player’s ID, but it should be set to the actual player object. To fix this, you can modify the TagHumanoid function to pass in the player object instead of the player ID, like so:

local function TagHumanoid(humanoid, player)
    local creator_tag = Instance.new("ObjectValue")
    local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant

    creator_tag.Value = player
    creator_tag.Name = "creator"
    creator_tag.Parent = humanoid
end

Then, in the car script, you can access the player’s leaderstats property using the player variable instead of plr , like so:

local function TagHumanoid(humanoid, player)
    local creator_tag = Instance.new("ObjectValue")
    local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant

    creator_tag.Value = player
    creator_tag.Name = "creator"
    creator_tag.Parent = humanoid
    player.leaderstats.Kill.Value += 1  -- increment player's kill score
end

if this doesnt work please explain what’s happening in more depth, thanks

1 Like

Thanks. I solved it two days ago!