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

How To Make A Leaderboard Stat A Valid Member Of A Player?

So I am attempting to add a line in a script that increases the player's "Cash" by a specific amount but how do I make the script below a valid member of a player?

game.Players.PlayerAdded:connect(function(plr)
	local stats = Instance.new("BoolValue",plr)
	stats.Name = "leaderstats"
	
	local cash = Instance.new("IntValue",stats)
	cash.Name = "Cash"
	cash.Value = 0
end)

Also, below is the script that I am trying to make give the cash to the player

leave = game.Workspace.leave

workspace.NPC1.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)
	if choice.Name == "Choice1" then 			--If the player takes the order
		player.Character.Torso.Anchored = false --Test (does nothing atm)
		game.Players.LocalPlayer.cash.Value = game.Players.LocalPlayer.Cash.Value +5
		wait(3)
		player.Character.Torso.Anchored = false --Test (does nothing atm)
	elseif choice.Name == "Choice2" then 		--If the player does not take the order
		player.Character.Torso.Anchored = false --Test (does nothing atm)
		wait(1)
		player.Character.Torso.Anchored = false --Test (does nothing atm)
		script.Parent.Parent.Parent.Humanoid.WalkToPoint = game.Workspace.leave.Position
		wait(5)
		script.Parent.Parent.Parent:Destroy()
	end
end)

2 comments

0

So, you're trying to make ur first script be in StarterGui or just straight under the player?

0

That script I have in the Workspace.

1 answer

✓ Accepted answer

The stats are within the Bool Value you created in the the first block of script

local stats = Instance.new("BoolValue",plr)
stats.Name = "leaderstats"

and the stat you have created has the bool value as a parent not the actual player itself so instead of:

game.Players.LocalPlayer.cash

it should be

game.Players.LocalPlayer.leaderstats.Cash

and I've noticed some of it is capitalised and some isnt make sure it is correctly capitalised or it wont work.

2 comments

0

Holy cow! It works! Thank you for taking time out of your day to assist me with my problem!

0

Its fine!

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