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

Leaderboard money goes to Minus (-)?

When I'm trying to make a script that removes amount of money on touch the money goes to minus (-) when you don't have enough.

local ting = 0

function onTouched(hit)

if ting == 0 then
ting = 1
check = hit.Parent:FindFirstChild("Humanoid")

if check ~= nil then

	local user = game.Players:GetPlayerFromCharacter(hit.Parent)
	local stats = user:findFirstChild("leaderstats")

	if stats ~= nil then
		local cash = stats:findFirstChild("money")
		cash.Value  = cash.Value -100
		wait(3)
	end

end

ting = 0
end

script.Parent.Touched:connect(onTouched)

3 comments

0

Do you mean it goes into the negative? Is that not what you wanted it to do? I need you to reword the question.

0

the ting goes skrrraa

0

Change 'cash.Value = cash.Value -100' to 'cash.Value = cash.Value - 100'

2 answers

Creeperhunter76 How can you prove that its a free model? Also kilu6n use this script:

local ting = 0 --debouncer

function onTouched(hit)
	if ting == 0 then --check for debounce
	ting = 1 --activate debounce 
	check = hit.Parent:FindFirstChild("Humanoid") --try to find the human that touched the button

	if check ~= nil then --if toucher is a human then to following

		local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
		local stats = user:findFirstChild("leaderstats") --Find moneyholder

		if stats ~= nil then --If moneyholder exists then
			local cash = stats:findFirstChild("Money") --Get money

				cash.Value = cash.Value - --How much you want, remove this




		end

	end

	ting = 0 --remove debounce
	end
end

script.Parent.Touched:connect(onTouched) --start checking for touchers

1 comment

0

I've legitimately seen this script before in a free model. You can see for yourself by searching up "money giver" in the toolbox

In this case it can be solved using a simple check to see if the value will still be positive once subtracted, adjustment can be seen on line 14:

function onTouched(hit)
	if ting == 0 then
		ting = 1
		check = hit.Parent:FindFirstChild("Humanoid")

		if check ~= nil then
			local user = game.Players:GetPlayerFromCharacter(hit.Parent)
	    		local stats = user:findFirstChild("leaderstats")
	
	    		if stats ~= nil then
	        		local cash = stats:findFirstChild("money")

				if ((cash.Value - 100) > 0) then
	        			cash.Value  = cash.Value -100
	        			wait(3)
				end
	    		end
		end
	
		ting = 0
	end
end

script.Parent.Touched:connect(onTouched)

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