Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my temperature script so buggy when i step into the part?

Asked by
iuclds 720 Moderation Voter
4 years ago

it literally goes sonic speed then slows down like I'm confused.

wait(1)
local plr = game.Players.LocalPlayer
local Char = plr.Character
local Hot = game.Workspace.Temps.Hot
local Cold = game.Workspace.Temps.Cold
local Temp = script.Parent.Parent.Temp

local temperature = {Hot,Cold}


wait(1)
-- // Hot x Cold \\ --


game.Players.LocalPlayer:WaitForChild("Temp")

Hot.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
repeat
    wait(5)
game.Players.LocalPlayer.Temp.Value = Temp.Value +1
until hit.Touched.Cold

    end
end)


wait(1)
-- // Cold x Hot \\ --
game.Players.LocalPlayer:WaitForChild("Temp")

Cold.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
repeat
    wait(5)
game.Players.LocalPlayer.Temp.Value = Temp.Value -1
until hit.Touched.Hot


    end
end)



wait(1)
-- Frozen Death
local k = Instance.new("Sound")
k.SoundId = "rbxasset://747238556"
if game.Players.LocalPlayer.Temp.Value < -400 then
    local children = Char:GetChildren()
for i = 1, #children do
    local child = children[i]
    if children:IsA("BasePart") or children:IsA("MeshPart") then
        children.Anchored = true
        if children:IsA("BodyColors") then
            HeadColor3 = Color3.fromRGB(34, 165, 205)
            LeftArmColor3 = Color3.fromRGB(34, 165, 205)
            LeftLegColor3 = Color3.fromRGB(34, 165, 205)
            HeadColor3 = Color3.fromRGB(34, 165, 205)
            RightArmColor3 = Color3.fromRGB(34, 165, 205)
            RightLegColor3 = Color3.fromRGB(34, 165, 205)
            TorsoColor3 = Color3.fromRGB(34, 165, 205)
            k:Play()

            if children:IsA("Decal") then
                Transparency = 1

                wait(7)

                Char.Humanoid.Health = 0
                Char.Humanoid.MaxHealth = 0
                wait(2)

                Temp.Value = 0

            end


end
end
end
end


1 answer

Log in to vote
1
Answered by
bluzorro 417 Moderation Voter
4 years ago

The reason your temp value goes up super sonic is because Touched events register every single touch, without a cooldown, and that's where you should add a cooldown/ debounce. Your script but with a debounce:

wait(1)
local plr = game.Players.LocalPlayer
local Char = plr.Character
local Hot = game.Workspace.Temps.Hot
local Cold = game.Workspace.Temps.Cold
local Temp = script.Parent.Parent.Temp

local temperature = {Hot,Cold}

local debounce = false


wait(1)
-- // Hot x Cold \\ --


game.Players.LocalPlayer:WaitForChild("Temp")

Hot.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not debounce then
    debounce = true
repeat
    wait(5)
game.Players.LocalPlayer.Temp.Value = Temp.Value +1
until hit.Touched.Cold
    wait(1)
    debounce = false
    end
end)


wait(1)
-- // Cold x Hot \\ --
game.Players.LocalPlayer:WaitForChild("Temp")

Cold.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not debounce then
    debounce = true
repeat
    wait(5)
game.Players.LocalPlayer.Temp.Value = Temp.Value -1
until hit.Touched.Hot

    wait(1)
    debounce = false
    end
end)



wait(1)
-- Frozen Death
local k = Instance.new("Sound")
k.SoundId = "rbxasset://747238556"
if game.Players.LocalPlayer.Temp.Value < -400 then
    local children = Char:GetChildren()
for i = 1, #children do
    local child = children[i]
    if children:IsA("BasePart") or children:IsA("MeshPart") then
        children.Anchored = true
        if children:IsA("BodyColors") then
            HeadColor3 = Color3.fromRGB(34, 165, 205)
            LeftArmColor3 = Color3.fromRGB(34, 165, 205)
            LeftLegColor3 = Color3.fromRGB(34, 165, 205)
            HeadColor3 = Color3.fromRGB(34, 165, 205)
            RightArmColor3 = Color3.fromRGB(34, 165, 205)
            RightLegColor3 = Color3.fromRGB(34, 165, 205)
            TorsoColor3 = Color3.fromRGB(34, 165, 205)
            k:Play()

            if children:IsA("Decal") then
                Transparency = 1

                wait(7)

                Char.Humanoid.Health = 0
                Char.Humanoid.MaxHealth = 0
                wait(2)

                Temp.Value = 0

            end


end
end
end
end
Ad

Answer this question