#Ice block

1 messages · Page 1 of 1 (latest)

west tundra
#

I got it to work where the block spawns on me and I’m trapped in the ice block but the ice block won’t delete itself or dissapear. And if I manually delete it my character is stuck without the movement reenabled

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

local ICEBLOCK_NAME = "IceBlock"
local FREEZE_TIME = 5

local TrapSound = ReplicatedStorage:FindFirstChild("IceTrapSound")
local PopSound = ReplicatedStorage:FindFirstChild("IcePopSound")
local PopParticle = ReplicatedStorage:FindFirstChild("IcePopParticle")

local function freezePlayer(character)
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    local torso = character:FindFirstChild("Torso")
    if not humanoid or not torso then return end

    if character:FindFirstChild("IsFrozen") then return end
    local freezeTag = Instance.new("BoolValue")
    freezeTag.Name = "IsFrozen"
    freezeTag.Parent = character

    print("Freezing player: " .. character.Name)

    -- Clone IceBlock
    local iceClone = ServerStorage:FindFirstChild(ICEBLOCK_NAME)
    if not iceClone then
        warn("IceBlock not found in ServerStorage!")
        freezeTag:Destroy()
        return
    end
    iceClone = iceClone:Clone()
    iceClone.Parent = workspace

    local middle = iceClone:FindFirstChild("Middle")
    if not middle then
        warn("IceBlock is missing Middle part!")
        iceClone:Destroy()
        freezeTag:Destroy()
        return
    end
    iceClone.PrimaryPart = middle
    iceClone:SetPrimaryPartCFrame(torso.CFrame)

    -- Trap sound
    if TrapSound then
        local ts = TrapSound:Clone()
        ts.Parent = torso
        ts:Play()
        Debris:AddItem(ts, 3)
    end

    -- Freeze movement
    local originalWalk = humanoid.WalkSpeed
    local originalJump = humanoid.JumpPower
    humanoid.WalkSpeed = 0
    humanoid.JumpPower = 0

    -- Wait freeze duration
    wait(FREEZE_TIME)

    print("Unfreezing player: " .. character.Name)

    -- Pop particle
    if PopParticle then
        local p = PopParticle:Clone()
        p.CFrame = middle.CFrame
        p.Parent = workspace
        p.Enabled = true
        Debris:AddItem(p, 2)
    end

    -- Pop sound
    if PopSound then
        local ps = PopSound:Clone()
        ps.Parent = torso
        ps:Play()
        Debris:AddItem(ps, 3)
    end

    -- Destroy IceBlock
    if iceClone and iceClone.Parent then
        iceClone:Destroy()
    end

    -- Restore movement
    humanoid.WalkSpeed = originalWalk
    humanoid.JumpPower = originalJump
    freezeTag:Destroy()
end

-- Connect Touched safely
script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    if character and character:IsA("Model") then
        freezePlayer(character)
    end
end)

oblique cape
#

U touch it many times, maybe that's why

#

Nvm

median venture
oblique cape
#

Wont change anything

median venture
#

Oh

#

Ye i cant even send it for some reason

oblique cape
#

The problem lies in how u handle frozen playersv

oblique cape
# west tundra Wdym?

To put this simply as possible everytime you touch this part it triggers a function that makes player freeze and after some certain of time unfreezes him which means that those cloned freeze blocks arent tied to a player. They are local for each function call and will be lost with each new touch on a part. Also, if u touch it again the first instance called in this function will still wait in his wait(), and it makes it out of the sync

#

Dunno if i explained it right

#

Basically this wait() in a function exists everytime u touch this part

#

U should keep track of every player separately and to unfreeze a player you should use task.spawn() because it does separated thread and inside of it a function that will not collide with others

#

Actually you should use Task.delay()

#

Its a better option for this case

west tundra
#

Im doing something wrong here

oblique cape
# west tundra Im doing something wrong here

Small template to give u an idea


local FrozenPlayers = {}

local function UnFreezePlayer(Character: Model)
    
end
local function FreezePlayer(Character: Model)
    
    
    --Time to unfreeze
    task.delay(FREEZE_TIME, function()
        UnFreezePlayer(Character)
    end)
end

Part.Touched:Connect(function(Touched: Part)
    local character = Touched.Parent
    if character and character:IsA("Model") and character:FindFirstChildOfClass("Humanoid") then
        freezePlayer(character)
    end
end)
#

Modify your code along this template and it should work (I think...)

west tundra
#

Nope still doesnt work