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

How do I make a click script that increases stats?

How do you do it? It looks like its good and it has no errors! Heres the code:

local ting = 0

local Part = script.Parent
function onClicked(click)
	if ting == 0 then 
		ting = 1
		local check = click.Parent:FindFirstChild("Humanoid")

		if check ~= nil then 

			local p = game.Players.LocalPlayer
			local sstats = game.Players.LocalPlayer.leaderstats

			if sstats ~= nil then 
				local cash = sstats:findFirstChild("Wins")
				cash.Value  = cash.Value  + 1
				p:ResetCharacter()
				wait(7)
			end 

		end 

		ting = 0
	end 

end 


Part.ClickDetector.MouseClick:Connect(onClicked)

2 comments

0

You can't change those values on a localplayer you have to m ake a serverscript

1

i did

1 answer

✓ Accepted answer

Your issue is

  1. there is no localplayer on a serverscript
  2. click is the player
  3. the check is unneccessary as a block cant click the part and it stops the script as player:FindFirstChild("Humanoid") returns nil bc it has to be .Character
  4. :ResetCharacter doesn't exist

here the fixed version:

local ting = 0

local Part = script.Parent
function onClicked(player)
	if ting == 0 then 
		if not player then return end
		ting = 1

		local sstats = player:FindFirstChild("leaderstats")

		if sstats ~= nil then 
			local wins = sstats:FindFirstChild("Wins")
			local points = sstats:FindFirstChild("Points")
			if wins then
				wins.Value  += 1
			end
			if points then 
				points.Value += 5
			end
			player:LoadCharacter()
			wait(7)
		end 



		ting = 0
	end 

end 


Part.ClickDetector.MouseClick:Connect(onClicked)

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