This Code Is For a Weight Lifting Simulator game and this script shows the Pop up effect when the player lifts the weight. Ui stops showing up when the Player dies and i want someone to tell me what i can do to fix it. the code is here:
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild(“PlayerGui”)
local screenGui = playerGui:WaitForChild(“Effects”)
local template = screenGui:WaitForChild(“StrengthEarned”)
local canClick = true
local cooldown = 2
local stayVisibleFor = 1
local bikeEquipped = false
local TweenService = game:GetService(“TweenService”)
local function createPopEffect()
local text = template:Clone()
text.Visible = true
text.Parent = screenGui
local screenSize = workspace.CurrentCamera.ViewportSize
local startX = math.random(100, screenSize.X - 100)
local startY = math.random(100, screenSize.Y - 200)
text.Position = UDim2.new(0, startX, 0, startY)
text.Rotation = math.random(0, 360)
text.TextTransparency = 0
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tweenGoals = {
Position = UDim2.new(0, startX, 0, startY - 100),
Rotation = text.Rotation + 180
}
local tween = TweenService:Create(text, tweenInfo, tweenGoals)
tween:Play()
delay(stayVisibleFor, function()
local fadeTweenGoals = { TextTransparency = 1 }
local fadeTween = TweenService:Create(text, tweenInfo, fadeTweenGoals)
fadeTween:Play()
fadeTween.Completed:Connect(function()
text:Destroy()
end)
end)
end
local function setupToolListeners()
local character = player.Character or player.CharacterAdded:Wait()
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") and child.Name == "Bike" then
bikeEquipped = true
child.Unequipped:Connect(function()
bikeEquipped = false
end)
end
end)
player.CharacterAdded:Connect(function(newChar)
character = newChar
bikeEquipped = false
end)
end
setupToolListeners()
local function onCharacterDied()
canClick = false
end
if player.Character then
local humanoid = player.Character:FindFirstChildOfClass(“Humanoid”)
if humanoid then
humanoid.Died:Connect(onCharacterDied)
end
end
player:GetMouse().Button1Down:Connect(function()
if canClick and bikeEquipped then
canClick = false
createPopEffect()
delay(cooldown, function()
canClick = true
end)
end
end)