(this is my first time posting in this website, so it may contain some mistakes in post)
I trying to make a local script (StarterPlayerScript):
-when player joined temp its 100 and cant increase and decrease beyond 100 and 0. temp its decreasing by 0.5 every 1 sec with print “Temp Decreased”.
-change frame background color when temp >= 75 or temp >= 50 or temp >= 25 or temp >= 1.
-kill player, award a badge and change frame background color to black when temp its 0.
-when player is on the part its stopping decreasing temp and start increasing temp by 1.5 every 1 sec with print “Temp Increased”. when player stopped being on the part its stop
but there some issues in this script:
1.It increase temp by every 0.001 sec but I wanted 1 sec.
2.it cant show a frame changing color
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character
local temp = 100
local decreasing = true
local increase = false
local lastUpdate = 0
local part = game.Workspace:WaitForChild("TempPart")
local frame = game.StarterGui.PlayerStatus.TempFolder.Status
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
increase = true decreasing = false
end
end)
part.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
increase = false decreasing = true
end
end)
RunService.RenderStepped:Connect(function()
if decreasing then
local currentTime = tick()
if currentTime - lastUpdate >= 1 then
temp = math.max(temp - 0.5, 0)
print("Temp Decreased")
lastUpdate = currentTime
if temp <= 0 then
-- Kill player
player.Character.Humanoid.Health = 0
-- Award badge
game:GetService("BadgeService"):AwardBadge(player.UserId, 1021320956854504) -- Replace with your badge ID
-- Change frame background color to black
frame.BackgroundColor3 = Color3.new(0, 0, 0)
decreasing = false
end
end
else
if increase then
temp = math.min(temp + 1.5, 100)
print("Temp Increased")
lastUpdate = tick()
if temp >= 75 then
frame.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
elseif temp >= 50 then
frame.BackgroundColor3 = Color3.fromRGB(0, 120, 180)
elseif temp >= 25 then
frame.BackgroundColor3 = Color3.fromRGB(0, 88, 132)
else
frame.BackgroundColor3 = Color3.new(1, 1, 1)
end
end
end
end)
if increase then
local currentTime = tick()
if currentTime - lastUpdate >= 1 then
temp = math.min(temp + 1.5, 0)
print("Temp Increased")
lastUpdate = currentTime
end
end
ok nevermind, im so stupid. just only i wanted to do its to prent local script with frame. now works perfectly. also i did some changes to this script:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character
local temp = 100
local decreasing = true
local increase = false
local lastUpdate = 0
local part = game.Workspace:WaitForChild("TempPart")
local frame = script.Parent
local tempText = frame.Parent.HP -- Changed to tempText
tempText.Text = temp
Players.PlayerAdded:Connect(function()
Players.CharacterAdded:Connect(function()
decreasing = true
temp = 100
tempText.Text = temp -- Update text when character is added
end)
end)
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
increase = true
decreasing = false
task.wait(1)
end
end)
part.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
increase = false
decreasing = true
task.wait(1)
end
end)
RunService.RenderStepped:Connect(function()
if decreasing then
local currentTime = tick()
if currentTime - lastUpdate >= 1 then
temp = math.max(temp - 0.5, 0) -- Changed to max to prevent negative values
print("Temp Decreased")
lastUpdate = currentTime
tempText.Text = temp -- Update text when temp decreases
if temp <= 0 then
-- Kill player
player.Character.Humanoid.Health = 0
-- Award badge
game:GetService("BadgeService"):AwardBadge(player.UserId, 1021320956854504) -- Replace with your badge ID
end
end
else
if increase then
local currentTime = tick()
if currentTime - lastUpdate >= 1 then
temp = math.min(temp + 1.5, 100) -- Changed to min to prevent exceeding maximum value
print("Temp Increased")
lastUpdate = currentTime
tempText.Text = temp -- Update text when temp increases
end
end
end
end)
while true do
wait(0.001)
if temp > 75 then
frame.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
elseif temp > 50 then
frame.BackgroundColor3 = Color3.fromRGB(0, 125, 188)
elseif temp > 25 then
frame.BackgroundColor3 = Color3.fromRGB(0, 95, 143)
elseif temp > 0 then
frame.BackgroundColor3 = Color3.fromRGB(0, 47, 71)
elseif temp == 0 then
frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
end
end