Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Money giver not working?

Once a player touches he or she is supposed to get XP. However it does not work

HELP!

script.Parent.Touched:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local leaderstats = Hit.Parent:FindFirstChild("leaderstats")
		if leaderstats ~= nil then
				print("leaderstats found!")
		  			  local XP = leaderstats:FindFirstChild("XP") 
		            if XP ~= nil then
								print("XP FOUND!")
						Hit.Parent.leaderstats.XP.Value = Hit.Parent.leaderstats.XP.Value +5
					end
		
		end
	end
end)

1 answer

Leaderstats are typically inside of the Player object, but you kept referencing to the player's character!

script.Parent.Touched:connect(function(Hit)
	local player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- Checks if it is a player
	if player then
		local leaderstats = player:findFirstChild("leaderstats")
		if leaderstats then
			leaderstats:WaitForChild("XP").Value = leaderstats:WaitForChild("XP").Value + 5 -- I used WaitForChild to ensure no errors could arise, claiming it's not there
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.