I'm trying to make my mana intValue rise the moment I hold g but it won't rise, I don't understand what I did wrong.. Maybe the way I used the while true do loop?
I don't know please help me with it.
The Code:
local UIS = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") local RE = RS.ManaEvent local plr = game.Players.LocalPlayer local mana = plr:WaitForChild("Stats").Mana local charging = false local function started(input,gameProcessed) UIS.InputBegan:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.G and charging == false then charging = true end end) local function ended(input,gameProcessed) UIS.InputEnded:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.G and charging == true then charging = false end end) UIS.InputBegan:Connect(started) UIS.InputEnded:Connect(ended) if charging == true then while true do wait(.03) if mana.Value == 100 then end end else mana.Value = mana.Value + 1 end end end
Thanks a lot.
I reread your code over and over and over again, and then I realized something, actually, a few errors... First of all(and the most important), you need to make the while true do part something like this: While charging == true and wait(.03) do
mana.Value = mana.Value + 1
end
And that's because the game has to keep looping through it seeing if it's true, if you just put "if charging == true then", it's only going to be looking at the origin value, not the new value! so here's what your code SHOULD look like: local RS = game:GetService("ReplicatedStorage") local RE = RS.ManaEvent local plr = game.Players.LocalPlayer local mana = plr:WaitForChild("Stats").Mana local charging = false
local function started(input,gameProcessed) UIS.InputBegan:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.G and charging == false then charging = true end
end)
local function ended(input,gameProcessed) UIS.InputEnded:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.G and charging == true then charging = false end end) UIS.InputBegan:Connect(started) UIS.InputEnded:Connect(ended) while charging == true and wait(.03) do if mana.Value == 100 then mana.Value = mana.Value elseif mana.Value < 100 and charging == true then
mana.Value = mana.Value + 1
end
end
end
end end end end