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

wanna keep button touched so people dont need to dance on it canu help ?

hey can someone help me i want it te keep touched it is for a button so people dont need to dance on the button

Door = script.Parent 
local debounce = false 

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 
function onTouched(hit) 
if debounce == false then 
local human = hit.Parent:findFirstChild("Humanoid") 
if (human == nil) then return end 
local player = getPlayer(human) 
debounce = true 
if (player == nil) then return end 
local stats = player:findFirstChild("leaderstats") 
local sp = stats:findFirstChild("Cash") -- replace nani with the stat that is getting removed/subtracted.
local ao = stats:findFirstChild("Multi")
local a = stats:findFirstChild("Rebirths")
local u = stats:findFirstChild("Ultra")
local m = stats:findFirstChild("Mega")
local p = stats:findFirstChild("Prestige")
local o = stats:findFirstChild("Levelc") -- replace nani with the stat that is getting removed/subtracted.
if sp == nil then return false end
if ao == nil then return false end 
if (sp.Value >=50) then -- replace 100 with stat cost
sp.Value = sp.Value - 50
o.Value = 0
print("Enough Money") 
ao.Value = ao.Value + 2*a.Value*m.Value*p.Value -- the multiplier you want
Door.BrickColor = BrickColor.new("Maroon")
wait(0) 
Door.BrickColor = BrickColor.new("Maroon")
debounce = false 
else debounce = false 
end 
end 

end 

connection = Door.Touched:connect(onTouched)

3 comments

0

You should format the code again. We can't see anything in your code.

0

dude put all your scripts in "Code Block". It looks messy...

0

all your codes I mean

1 answer

local debounce = false -- This was missing. Made your code easier to see

function getPlayer(humanoid)
	local players = game.Players:children()

	for i = 1, #players do
		if players[i].Character.Humanoid == humanoid then
			return players[I]
		end
	end
	return nil
end--

function onTouched(hit)
	if debounce == false then
		local human = hit.Parent:findFirstChild("Humanoid")
		if (human == nil) then
			return 
		end
		--
		local player = getPlayer(human)
		debounce = true 
		if (player == nil) then
	return 
end

local stats = player:findFirstChild("leaderstats") 
local sp = stats:findFirstChild("Cash") -- replace nani with the stat that is getting removed/subtracted.
local ao = stats:findFirstChild("Multi")
local a = stats:findFirstChild("Rebirths")
local u = stats:findFirstChild("Ultra")
local m = stats:findFirstChild("Mega") 
local p = stats:findFirstChild("Prestige") 
local o = stats:findFirstChild("Levelc") -- replace nani with the stat that is getting removed/subtracted. 

if sp == nil then 
	return false
end--

if ao == nil then
	return false
end--

if (sp.Value >=50) then -- replace 100 with stat cost 
	sp.Value = sp.Value - 50 
	o.Value = 0 
	print("Enough Money") 
	ao.Value = ao.Value + 2
	a.Value = Value * p.Value -- the multiplier you want Door.BrickColor = BrickColor.new("Maroon") wait(0) Door.BrickColor = BrickColor.new("Maroon") debounce = false else debounce = false end end
end--

connection = Door.Touched:connect(onTouched)

4 comments

0

I also fixed Line 49, if your script isn't working as intended, then its probably that line

0

if i add this script then it is broken

0

Idk then, all I did was add a debounce that you didn't specify. Maybe ask the one that helped you make the script

0

the guy dont know him self

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