Hi guys, I'm learning scripting and now I'm with a trouble: I've created the leaderstats:

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("IntValue", player)
	stats.Name = "leaderstats"
	
	local Points = Instance.new("IntValue",stats)
	Points.Name = "Points"
	
	local Wins = Instance.new("IntValue",stats)
	Wins.Name = "Wins"
end)

(this is a normal script at the Workspace)

then I put a LocalScript in the StarterPack with a system that changes the wins and the points

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local leaderstats = Player.leaderstats

local Points = leaderstats.Points
local Wins = leaderstats.Wins

Wins.Value = 1

Points.Changed:connect(function()
	if Points.Value >= Wins.Value*50 then
		Points.Value = Points.Value - Wins.Value*50
		Wins.Value = Wins.Value+1
	end
end)

Until here r all ok, when I manually change the Points to 50, the Wins goes to 2 and the points reset, when I put 50 manually again, the Points become 50.

But I created a Part in the Workspace and put a normal script:

d = true

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if d == true and humanoid ~= nil then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local Points = Player.leaderstats.Points
		local Wins = Player.leaderstats.Wins
	
		if d == true then
			d = false
			Points.Value = Points.Value+10
			wait(1)
			d = true
		end
	end
end)

When i touch the part, i get 10 points, ok. But when i get +1 win, the points aparently resets, but when i touch the part again, the points didn't reseted and just add +10 at the old value.. Example: I've touched the part 5 times and got 50 points; Wins = 2 now; Points = 0

I touch the part again and got 10 points; Wins = 2; Points = 60

I wanted to the points reset, why isn't working?

Edit 1:

I've changed the local script that was in the StarterPack to a normal script at the workspace:

local Players = game:GetService("Players")
local Player = Players:WaitForChild("DanielGamerXD")
local leaderstats = Player.leaderstats

local Points = leaderstats.Points
local Wins = leaderstats.Wins

Wins.Value = 1

Points.Changed:connect(function()
	if Points.Value >= Wins.Value*50 then
		Points.Value = Points.Value - Wins.Value*50
		Wins.Value = Wins.Value+1
	end
end)

now it Works perfectly, but how can i script in way that it can be applied to other players wich nickname are different than mine (i've specified my character at the 2nd line)?

Edit 2:

I've changed the first script to this, and deleted the 2nd script, now its works properly:

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("IntValue", player)
	stats.Name = "leaderstats"
	local Points = Instance.new("IntValue",stats)
	Points.Name = "Points"
	local Wins = Instance.new("IntValue",stats)
	Wins.Name = "Wins"
	
	
	local Player = player
	local leaderstats = Player.leaderstats
	local Points = leaderstats.Points
	local Wins = leaderstats.Wins
	Wins.Value = 1

	Points.Changed:connect(function()
		if Points.Value >= Wins.Value*50 then
			Points.Value = Points.Value - Wins.Value*50
			Wins.Value = Wins.Value+1
		end
	end)
end)

2 comments

0

You are changing the points from a local script, so the changes are not replicated

0

thanks