Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm trying to make my mana intValue rise when I press g, it's not working?

Asked by
epicnt 13
4 years ago

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.

0
oops didn't fix the gameProcessed thing epicnt 13 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
Thanks I'll try it. epicnt 13 — 4y
0
It still doesn't work? epicnt 13 — 4y
0
I fixed it epicnt 13 — 4y
0
Mkay CataclysmicDev 46 — 4y
Ad

Answer this question