#power up timer resetting is not working after touching the part again, everything else works
4 messages · Page 1 of 1 (latest)
ok
-- Get the necessary services and objects
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local GreenGlowingOrbs = Workspace:WaitForChild("GreenGlowingOrbs")
local PowerupResetEvent = game.ReplicatedStorage:WaitForChild("PowerupResetEvent")
-- Constants
local JUMP_HEIGHT = 18
local DEFAULT_JUMP_HEIGHT = 7.2
local POWERUP_DURATION = 15
-- Function to activate the power-up when the player touches an orb
local function activatePowerUp(player)
-- Check if the player already has the power-up active
local currentJumpHeight = player.Character.Humanoid.JumpHeight
if currentJumpHeight == JUMP_HEIGHT then
-- Reset the jump height to the default value
player.Character.Humanoid.JumpHeight = DEFAULT_JUMP_HEIGHT
else
-- Set the jump height to the power-up value
player.Character.Humanoid.JumpHeight = JUMP_HEIGHT
-- Start the power-up timer
local powerUpTimeLeft = POWERUP_DURATION
repeat
-- Update the power-up time left value
PowerupResetEvent:FireClient(player, powerUpTimeLeft)
-- Wait for 1 second
wait(1)
-- Decrease the power-up time left
powerUpTimeLeft = powerUpTimeLeft - 1
until powerUpTimeLeft <= 0
-- Reset the jump height to the default value after the power-up duration
player.Character.Humanoid.JumpHeight = DEFAULT_JUMP_HEIGHT
end
end
-- Connect the power-up activation function to each orb's touch event
for _, orb in ipairs(GreenGlowingOrbs:GetChildren()) do
orb.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if player then
activatePowerUp(player)
end
end)
end
This server-side script activates the power-up when a player touches an orb by setting their jump height to 18. It then starts a loop that updates the power-up time left value and communicates it to the client using the PowerupResetEvent. After the power-up duration (15 seconds), the player's jump height is reset to the default value.
Make sure to create the PowerupResetEvent in a Folder named "ReplicatedStorage" in your game hierarchy. Also, ensure that the part the player touches is properly positioned and named "GreenGlowingOrb".
On the client-side, you'll need to listen for the PowerupResetEvent and update the GUI countdown timer accordingly.
** You are now Level 4! **