-
What do you want to achieve? A script where the energy value decreases by 2 every 0.1 seconds while the button is held
-
What is the issue? the script doesn’t stop after the value changes to off
-
What solutions have you tried so far? I tried doing while loops, repeat loops and I tried combining them but nothing has worked so far
here’s the script that doesn’t work(server)
while value == "LeftOn" do
repeat
plrcharacter:FindFirstChild("Energy").Value -= 2
wait(0.1)
until value == "LeftOff"
end
here’s the entire script(server)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage.Daisy.Quake
local quaking = false
local leftQuake
local leftDebounces = {}
local leftConnection
event.OnServerEvent:Connect(function(player, value)
local plrcharacter = player.Character
if value == "LeftOn" then
quaking = true
plrcharacter:FindFirstChild("CanAttack").Value = false
plrcharacter:FindFirstChild("CanRegen").Value = false
leftQuake = ReplicatedStorage.Daisy.LeftQuake:Clone()
leftQuake.CanCollide = false
wait(0.5)
leftQuake.CFrame = plrcharacter.LeftHand.CFrame * CFrame.new(0,-8,0)
leftQuake.Parent = workspace
for i, v in pairs(plrcharacter.LeftHand:GetDescendants()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end
local weld = Instance.new("WeldConstraint")
weld.Part0 = plrcharacter.LeftHand
weld.Part1 = leftQuake
weld.Parent = leftQuake
leftConnection = leftQuake.Touched:Connect(function(target)
local character = target.Parent
if not character then return end
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if table.find(leftDebounces, character) then return end
table.insert(leftDebounces, character)
local targetPlayer = game.Players:GetPlayerFromCharacter(character)
local bv = Instance.new("BodyVelocity")
bv.Velocity = CFrame.new(plrcharacter.HumanoidRootPart.Position, character.UpperTorso.Position).LookVector * 100 + CFrame.new(plrcharacter.HumanoidRootPart.Position, character.UpperTorso.Position).UpVector * -5
bv.Parent = character.UpperTorso
game.ReplicatedStorage.CamEvents.CamShake:FireClient(targetPlayer, "Shake", "Explosion")
character:FindFirstChild("CanAttack").Value = false
wait()
character:WaitForChild("RagdollR15"):FindFirstChild("Activate").Value = true
wait(0.25)
bv:Destroy()
for i = 1,25 do
character.Humanoid:TakeDamage(1)
wait(0.1)
end
wait(3)
character:WaitForChild("RagdollR15"):FindFirstChild("Activate").Value = false
character:FindFirstChild("CanAttack").Value = true
if character.UpperTorso:FindFirstChild("BodyVelocity") then
character.UpperTorso:FindFirstChild("BodyVelocity"):Destroy()
end
table.clear(leftDebounces, character)
end
end)
end
if value == "LeftOff" then
for i, v in pairs(plrcharacter.LeftHand:GetDescendants()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
quaking = false
leftQuake:Destroy()
plrcharacter:FindFirstChild("CanAttack").Value = true
plrcharacter:FindFirstChild("CanRegen").Value = true
end
while value == "LeftOn" do
repeat
plrcharacter:FindFirstChild("Energy").Value -= 2
wait(0.1)
until value == "LeftOff"
end
end)