Increase value by clicking on the screen

Hello everyone, I was using the mousebuttonclick system until now, but I think it makes the game simple now. I want to disable the button so that the same event happens when they click on the screen, not a button. This is the code of the button, what should I do?

local plr = game.Players.LocalPlayer
local char = plr.Character

local debounce = false

-- JumpPower değerindeki değişiklikleri takip eden fonksiyon
local function onJumpPowerChanged(newValue)
	char.Humanoid.JumpPower = newValue
end

-- JumpPower değeri değiştiğinde onJumpPowerChanged fonksiyonunu çalıştıran fonksiyon
plr.leaderstats.JumpPower.Changed:Connect(onJumpPowerChanged)

script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
		if plr.leaderstats.Rebirths.Value == 0 then
			plr.leaderstats.JumpPower.Value += 1
		end

		if plr.leaderstats.Rebirths.Value == 1 then
			plr.leaderstats.JumpPower.Value += 10
		end

		if plr.leaderstats.Rebirths.Value == 2 then    
			plr.leaderstats.JumpPower.Value += 20
		end

		if plr.leaderstats.Rebirths.Value == 3 then    
			plr.leaderstats.JumpPower.Value += 30
		end        

		if plr.leaderstats.Rebirths.Value == 4 then            
			plr.leaderstats.JumpPower.Value += 40      
		end

		debounce = false
	end
end)

2 Likes

You should just Multiply the Rebirth Value by 10 and Add it as the JumpPower, when the Player has 0 as their Rebirth, you can use math.max to set the number to 1 when the number is less than 1

plr.leaderstats.JumpPower.Value += math.max(1, plr.leaderstats.Rebirths.Value * 10)

So Basically this:

script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
        plr.leaderstats.JumpPower.Value += math.max(1, plr.leaderstats.Rebirths.Value * 10)
		debounce = false
	end
end)

Should Simpify your code to just one line instead of multiple conditions, but back on track you would need to detect the UserInputType of the Input using UserInputService.

In this case, you would need to use UserInputService.InputChange to Detect a Change in Input, then check if the InputObject’s UnserInputType is a certain Enum, like so:

UserInputService.InputChanged:Connect(function(input, gpe)
    -- 1st Paramter is the InputObject
    -- GameProccessedEvet is used to check if the Click was in the game
    if input.UserInputType = Enum.UserInputType.MouseButton1 then -- when they click the Mouse Button
        -- code
    end
end)

However if you want to it to work on Different Devices, you may need to add different Input Types, you would also need to place this in StarterPlayerScripts

3 Likes

What exactly is the problem
I don’t get it?

1 Like

the problem is checking for every rebirth value is very inefficient and impossible (assuming 4 isn’t the max) so i do agree with @DasKairo with trying to simplify the code

2 Likes

And how are you checking out right now?

2 Likes

I don’t get why you need to get every players start at once

2 Likes

Thank u sir, it very usefull for me, ı am grateful, so How can we make these events happen by clicking on the screen? I don’t want to use mousebutton anymore

1 Like

THERE is no other way to detect clicking on screen bruh

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.