Need help with script

In this code, I am trying to make it so that when you hold left click, every second your strength will go up one.
local GUI = game.StarterGui

local Values = Instance.new(“Folder”)

Values.Name = “Values”

Values.Parent = workspace

local Strength = Instance.new(“IntValue”)

Strength.Name = “Strength”

Strength.Parent = Values

Strength.Value = 0

local StrengthLimit = Instance.new(“IntValue”)

StrengthLimit.Name = “StrengthLimit”

StrengthLimit.Parent = Values

StrengthLimit.Value = 10

GUI.ScreenGui.TextLabel.Text = Strength.Value…“/”…StrengthLimit.Value

local Tool = game.ReplicatedStorage.Test

Tool.Equipped:Connect(function(Mouse)

Mouse.Button1Down:Connect(function()

Strength.Value = Strength.Value + 1

wait(1)

end)

end)

There are no errors in this but it isn’t working.

That’s because MouseButton1Down will only fire once, you can use a while loop to keep going when it first goes down, and stop once MouseButton1Up is fired.

I recommend reading this: Hold-Click Tools - #3 by VicPoweredODST

I changed it to Button1Click and it still isnt doing anything. The Text Label isnt changing either.

That’s not what I said? You’re going to need to make a while loop to change the power while the button is down. MouseButton1Down is an event, and will only be fired as soon as the mouse goes down… It will not be repeated until the user stops clicking, and clicks again.

You’ll need a while loop to fire while the MouseButton1 is down.

Like this

local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouseDown = false

mouse.Button1Down:connect(function()
    mouseDown = true
end)

mouse.Button1Up:connect(function()
    mouseDown = false
end)

while true do
    wait()
    if mouseDown then
    	print("do something while mouse is down")
    end
end

I meant to do Clicks not Hold mb

StarterGui is a place holder for developers to hold GUI that should be cloned to players when they join. Any scripts that edit a GUI in StarterGui will not update for players.

1 Like

Where should I put the GUI then?

The GUIs are stored in a sub folder of every player’s Player Instance in Players.

Im only a beginner/intermidiate scripter so idek what that means

image
The GUI a player sees is stored in the PlayerGui Folder in their Player.

1 Like