I have a game Code Hunters II and the money 'Tokens' when I purchase speed it gives me speed, but gives me the tokens back. How do I fix this? PLEASE HELP!

leaderstats:

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

Token Giver:

mount = 1
timedelay = 3
currencyname = "Tokens"

while true do
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end

The Store:

plr = game.Players.LocalPlayer
gold = plr:findFirstChild("leaderstats")
sp = gold:findFirstChild("Tokens")  --Change to the name of the points 
script.Parent.MouseButton1Click:Connect(function(onClick)
	if sp == nil then return false end 
	if (sp.Value >=13) then --Amount of points needed 
	sp.Value = sp.Value - 13 --Amount of points needed 
	plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed + 1
	script.Parent.Text = 'Purchase Complete!'
	wait(3)
	script.Parent.Text = '+1 Speed {Price: 13 Tokens}'
	else
		plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed + 0
		script.Parent.Text = 'Purchase Declined!'
		wait(3)
		script.Parent.Text = '+1 Speed {Price: 13 Tokens}'
	end
end)

1 comment

0

Try making a RemoteFunction to add or take points. It'll clean up this code a lot.