local DrainStamina = game:GetService("TweenService"):Create(Stamina,TweenInfo.new(5),{Value = 0})
if hold == true then
DrainStamina:Play()
Character:SetAttribute("Attacking",true)
else
DrainStamina:Pause()
Character:SetAttribute("Attacking",false)
end
Nothing seems out of place with the code, unless you’re forgetting to change the hold value which in that case you’ll need to do this:
local DrainStamina = game:GetService("TweenService"):Create(Stamina,TweenInfo.new(5),{Value = 0})
if hold == true then
DrainStamina:Play()
Character:SetAttribute("Attacking",true)
hold = false
else
DrainStamina:Pause()
Character:SetAttribute("Attacking",false)
hold = true
end
I used UIS.inputbegan and ended
The problem will not be in the tween, check other places or provide code with the rest of the functionality.
uis.InputBegan:Connect(function(input,gamepro)
if gamepro then return end
if input.KeyCode == Enum.KeyCode.E then
remote:FireServer("Barrage",true)-- hold = true
end
end)
uis.InputEnded:Connect(function(input,gamepro)
if gamepro then return end
if input.KeyCode == Enum.KeyCode.E then
remote:FireServer("Barrage",false)-- hold = false
end
end)
That’s not all, we also need the part with remote handler, how the tween is created and everything else what could be connected to this issue.
remote.OnServerEvent:Connect(function(player,Input,hold)
local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local inUse = Character:WaitForChild("inUse").Value
local attacking = Character:GetAttribute("Attacking")
if Input == "Barrage" then
local DrainStamina = game:GetService("TweenService"):Create(Stamina,TweenInfo.new(5),{Value = 0})
if hold == true then
DrainStamina:Play()
Character:SetAttribute("Attacking",true)
elseif hold == false then
DrainStamina:Pause()
Character:SetAttribute("Attacking",false)
end
end
end)
Inside stamina displayer script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Stamina = ReplicatedStorage.Stamina
Stamina.Changed:Connect(function()
if Stamina.Value >= 1 then
game:GetService("TweenService"):Create(script.Parent,TweenInfo.new(0.25),{Size = UDim2.new(Stamina.Value/100,0,1,0)}):Play()
elseif Stamina.Value <= 0 then
local Tween = game:GetService("TweenService"):Create(script.Parent,TweenInfo.new(5),{Size = UDim2.new(1,0,1,0)})
Tween:Play()
Tween.Completed:Connect(function()
ReplicatedStorage.Remote:FireServer("Stamina")-- stamina.value = 100
end)
end
end)
There’s the issue. Everytime a remote is called, you’re creating new tween for stamina drain.
This means:
- when remote is called first time with hold = true, the tween is created and played
- when remote is called with hold = false, new tween is created and never turned on, however the old one is still running
Your solution to this problem is caching the existing stamina drain using table
...
local staminaDrainMap = {}
remote.OnServerEvent:Connect(function(player,Input,hold)
local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local inUse = Character:WaitForChild("inUse").Value
local attacking = Character:GetAttribute("Attacking")
if Input == "Barrage" then
local drainStamina = staminaDrainMap[player]
if (drainStamina == nil) then -- Also add check if tween is finished so new could be created anyways
drainStamina = game:GetService("TweenService"):Create(Stamina,TweenInfo.new(5),{Value = 0})
staminaDrainMap[player] = drainStamina
end
if hold == true then
drainStamina:Play()
Character:SetAttribute("Attacking",true)
elseif hold == false then
drainStamina:Pause()
Character:SetAttribute("Attacking",false)
end
end
end)
Thanks but how to fix it???
About the tween check I’m not sure, currently I’m unable to check it myself, so take a look onto docs, and find out how to check if the drainStamina tween is finished or not. The condition can be simply added to the first condition drainStamina == nil or drainStamina:IsFinished()
or something like that.
I think this should work:
local DrainStamina = game:GetService("TweenService"):Create(Stamina,TweenInfo.new(5),{Value = 0})
remote.OnServerEvent:Connect(function(player,Input,hold)
local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local inUse = Character:WaitForChild("inUse").Value
local attacking = Character:GetAttribute("Attacking")
if Input == "Barrage" then
if hold == true then
DrainStamina:Play()
Character:SetAttribute("Attacking",true)
elseif hold == false then
DrainStamina:Pause()
Character:SetAttribute("Attacking",false)
end
end
end)
This will be unfortunately working only for one player on the server, since you’re creating a shared tween.
This means that player 1 can toggle it on, and player 2 can toggle it off.
It actually works, it’s the complex problem?
Oof yea that was a bad suggestion, but I think I have an idea that might work although I need to know where the stamina value is located @NoobyRequiem
The provided code from @JohhnyLegoKing will work only for you, my solution should work for all players on server.
StarterGui but it working now, Thanks for your help anyway
@Cloudy71 is right though, it will only work if the game has 1 player only
Also in StarterGui as in game.StarterGui.Stamina?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.