Hi so i have this script here and it works fine but when ever your power hits 100 it show a text label like it supposed to but when i press e it does not set my Power Attrabute to 0 like its supposed to why is this
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local PowerBar = script.Parent.PowerBar.Bar
local MaxPower = 100
local IsPromptActive = false
PowerBar.Size = UDim2.new(0, 0, 1, 0) -- Start with an empty power bar
local humanoid = Character:WaitForChild("Humanoid")
humanoid:SetAttribute("Power", 0) -- Start with 0 power
local function GiveTool()
-- Create and give the player a tool (replace this with your actual tool creation logic)
local tool = Instance.new("Tool")
tool.Name = "YourToolName"
tool.RequiresHandle = true
tool.RequiresCursor = true
tool.Parent = Player.Backpack
end
local function ShowPrompt()
local ButtonPrompt = Instance.new("TextLabel")
ButtonPrompt.Name = "ButtonPrompt"
ButtonPrompt.Size = UDim2.new(0, 100, 0, 50)
ButtonPrompt.Position = UDim2.new(0.5, -50, 0.8, 0)
ButtonPrompt.BackgroundColor3 = Color3.new(0, 0, 0)
ButtonPrompt.BackgroundTransparency = 0.5
ButtonPrompt.BorderSizePixel = 0
ButtonPrompt.Text = "[E]"
ButtonPrompt.TextColor3 = Color3.new(1, 1, 1)
ButtonPrompt.TextSize = 24
ButtonPrompt.Parent = script.Parent
local promptAction
promptAction = UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.E and not gameProcessedEvent then
local currentPower = humanoid:GetAttribute("Power")
if currentPower >= MaxPower and not IsPromptActive then
humanoid:SetAttribute("Power", 1) -- Reset Power to 0
PowerBar.Size = UDim2.new(0, 0, 1, 0)
ButtonPrompt:Destroy()
IsPromptActive = false
GiveTool()
promptAction:Disconnect() -- Disconnect the input listener
end
end
end)
IsPromptActive = true
end
local function UpdatePowerBar()
while true do
local currentPower = humanoid:GetAttribute("Power")
if currentPower < MaxPower then
humanoid:SetAttribute("Power", currentPower + 1) -- Increment power by 1
local newScale = currentPower / MaxPower
PowerBar.Size = UDim2.new(newScale, 0, 1, 0)
elseif currentPower >= MaxPower and not IsPromptActive then
ShowPrompt()
end
wait(0.1) -- Adjust the delay to control the rate of power increase
end
end
spawn(UpdatePowerBar)