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

I need help with this script that adds money directly to the player on touch. Please help?

I am making a sandbox tycoon and i have a money collector that adds money directly to the players cash, but it only works on the first one that touches it. Please help!

function onTouched(hit) 
    if hit.Name == "Cash" then
    game:GetService("ReplicatedStorage").Owner1.OnServerEvent:connect(function(player)
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + hit.Value.Value --Gives money based on value in money
	hit:remove()
    end)
end
end
script.Parent.Touched:Connect(onTouched)

Also, for some reason it adds a touch interest in the part that has the script in it.

3 comments

0

Bump

0

Bump

0

Bump

1 answer

Im not sure what your asking for but this script gives you cash!

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("Cash") 
			cash.Value  = cash.Value +10000000 
			wait(2) 
		end

	end

	ting = 0 
	end

end

script.Parent.Touched:connect(onTouched)

5 comments

0

Thanks, but thats not what i was asking, im saying the collector i have works ontouch and adds the value that is in the thing that touches it to your cash directly, but it only works for the first "cash" that touches it and then when they touch it, it doesnt do anything

0

Add the Debounce

0

Do you mean just add wait? Because ive tried that, but it didnt work and it removes it instantly anyways so how would it help?

0

No Wait and debounce are diffrent

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