Points leaderstats doesnt work well

i have guess the anime game and there is a problem with the points leaderstats, the problem is that when i go with my friend to the next stage at the same time its gives only point to one of us.

script:

local part = script.Parent
local canGet = true

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = game.Players:FindFirstChild(otherPart.Parent.Name)
		if player and canGet then
			canGet = false
			player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
			wait(50)
			canGet = true
		end
	end
end

part.Touched:Connect(onTouch)

this may or might not be regarding the problem, but you should change player to

local player = game.Players:GetPlayerFromCharacter(otherParent.Parent)

He’s probably not literally meaning “otherParent” he’s probably assuming you stored that in a variable.

Also is this a free model you used?

It’s because of the canGet value, which is false after the first player touched it. The second player is able to get the point after the delay of 50 seconds.

I’m not an actual scripter, but this may work:

local part = script.Parent
local Players = game:GetService("Players")
local canGet = {}

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = Players:GetPlayerFromCharacter(otherPart.Parent)
		if player and not canGet[player.UserId] then
			canGet[player.UserId] = true
			player.leaderstats.Points.Value += 1
			wait(50)
			canGet[player.UserId] = nil
		end
	end
end

part.Touched:Connect(onTouch)
1 Like

i think its from a youtube video


help

My bad, I meant otherPart.Parent

Ah oops, will change that. Thanks.

You haven’t defined the variable Players.

local Players = game:GetService('Players')
1 Like

try using game:GetService(“Players”) or game.Players instead of Players

That’s what @sagiv200421 mentioned above. :slightly_smiling_face:

2 Likes