Leaderstats problem

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? leaderstats increased when part is touched with morph

  2. What is the issue? with the morph the leaderstats wont increase when the part is touched

  3. What solutions have you tried so far? tried to look in the script but I have no idea what’s the problem

I followed GnomeCode’s tutorial on how to rig and animate custom characters but when the morph touches the part that is supposed to increase the leaderstats it doesn’t increase.

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.Souls.Value = player.leaderstats.Souls.Value + 1 

		wait(1) 

		canGet = true
	end
end

end

part.Touched:Connect(ontouch)

this is the script that increases the leaderstats when touched

You should try use :GetPlayerFromCharacter() instead of using game.Players[charactername]

New:

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

Old:

local player = game.Players:FindFirstChild(otherPart.Parent.Name)
2 Likes

If you have don’t make the leaderstats folder:
Make a script and put in the ServerScriptService:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	local Souls = Instance.new("IntValue",plr)
	Souls.Name = "Souls"
	Souls.Value = 0
end)

And the solution:

local canGet = true
script.Parent.Touched:Connect(function(TouchedPart)
	local player = game.Players:FindFirstChild(TouchedPart.Parent.Name)
	if player and canGet then 
		canGet = false
		player.leaderstats.Souls.Value += 1
		wait(1) 
		canGet = true
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.