#simple yet something i cant solve

1 messages · Page 1 of 1 (latest)

thick ice
#

so this code:


local particle = part:FindFirstChild("ParticleEmitter")

local sound = part:FindFirstChild("Break bones #4")



local Player = game:GetService("Players")
local players

Player.PlayerAdded:Connect(function(player)
    players = player
end)

local teams = game:GetService("Teams")

local team1 = teams:FindFirstChild("Viking Brutes")
local team2 = teams:FindFirstChild("Vikings")
local team3 = teams:FindFirstChild("Viking Archers")

local Ttable = {team1 , team2 , team3}





local canTouch = true

local SPEED



part.Touched:Connect(function(hit)
    local canDo = true 

    for _, p in ipairs(players:GetChildren()) do
        if p.Team == team1 or p.Team == team2 or p.Team == team3 then
            canDo = false  
            break        
        end
    end

    if canTouch and canDo == true then

        
        
        local character = hit:FindFirstAncestorOfClass("Model")
        if not character then return end

        sound:Play()

        if particle then
            particle.Transparency = NumberSequence.new(0)
            task.delay(1, function()
                particle.Transparency = NumberSequence.new(1)
            end)
        end

        local humanoid = character:FindFirstChildOfClass("Humanoid")
        if not humanoid or humanoid.Sit then return end 
        
        local player = game.Players:GetPlayerFromCharacter(character)
        


        local originalJumpPower = humanoid.JumpPower
        local originalWalkSpeed = humanoid.WalkSpeed
        
        local function getSpeed()
            SPEED = humanoid.WalkSpeed
        end
        getSpeed()

        humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
        humanoid.Sit = true
        humanoid.JumpPower = 0
        humanoid.WalkSpeed = 0


        local forceSit = true
        local sitLoop = task.spawn(function()
            while forceSit and humanoid and humanoid.Parent do
                humanoid.Sit = true
                task.wait()
            end
        end)
        
        
        canTouch = false
        task.wait(3)
        canTouch = true
        humanoid.JumpPower = originalJumpPower
        humanoid.WalkSpeed = SPEED
        humanoid.Sit = false 

        task.cancel(sitLoop)
    end
end)

worked up until the moment i added the for loop to check if ur in one of said teams, now after i added it, it doesnt work at all

also another issue is that after 3 seconds pass it doesn't restore ur speed back to what it did befoer

green perch
#

So you're checking to see if any players in the game are on those teams, and if so, they cannot canDo?

thick ice
#

yes. to make this hitbox part only be able to hit those who are not in one of those teams

green perch
thick ice
pseudo forumBOT
#

studio** You are now Level 2! **studio

thick ice
#

any idea on how to fix this

eager bridge
#

and/or warnings?

thick ice
#

no it just

#

doesn't work shrug

eager bridge
#

💔

#

Try debugging it first

thick ice
#

imma try again maybe im blind

eager bridge
#

im too lazy to read

#

💔

thick ice
#

no errors