#(very new at scripting to lua) Need help for my script

43 messages · Page 1 of 1 (latest)

heavy holly
#

Ok so what im trying to make a script where once a player dies 3 times, he gets sent to the "main lobby". Since im new and I suck at scripting I need help from you guys. very appreciated if helped

ocean crown
#
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")


local LOBBY_PLACE_ID = 123456789
local DEATH_MAX = 3


local deathCounters = {}



local function onCharacterAdded(character: Model, player: Player)
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid then
        player:Kick("Could not find Humanoid.")

        return
    end

    humanoid.Died:Once(function()
        deathCounters[player] += 1

        if deathCounters[player] < DEATH_MAX then
            return
        end
        -- Player has reached maximum death allowance.
  
        local success, response = pcall(TeleportService.TeleportAsync, TeleportService, LOBBY_PLACE_ID, {player})
        if success then
            return
        end
        -- Teleport failed.
        
        player:Kick("Teleport failed.")

        error(response)
    end)
end

local function onPlayerAdded(player: Player)
    deathCounters[player] = 0

    local character = player.Character
  
    if character then
        onCharacterAdded(character, player)
    end

    player.CharacterAdded:Connect(function(character)
        onCharacterAdded(character, player)
    end)
end

local function onPlayerRemoving(player: Player)
    deathCounters[player] = nil
end



for _, player in Players:GetPlayers() do
    onPlayerAdded(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
heavy holly
#

hm

rough hamletBOT
#

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

ocean crown
#

No way I just made that mistake 🤦

#

@heavy holly, fixed

heavy holly
#

alr ima try

#

not tping me apparently

#

nothing in the log

ocean crown
#

Type of script and where?

#

Keep in mind that TeleportService does not work in Roblox Studio

heavy holly
#

join this and try to reset 3 times

ocean crown
heavy holly
ocean crown
#

Answer the question, man

heavy holly
#

😭

ocean crown
#

Send photo of the script you inserted into the Explorer

heavy holly
#

oh

#

its in serverscriptservice

heavy holly
ocean crown
#

Oop, I see the problem...

#

Try now, @heavy holly

heavy holly
#

alr

#

aaaaand still nothing

ocean crown
#

Fixed, @heavy holly

#

This is what blind scripting is like, lol

heavy holly
#

me try now

#

YES

#

ITS WORKS

#

ITS WORKS

#

IT WORKS

#

YESSSSSSSSSSSSSSSSSSSSSSSSSSSS

#

ASKJDRHTSEIU4TY4E8T9PH4896NIUOKHNFTS

heavy holly
heavy holly
#

i need a lil help again

#

I want to make it so taht once a player dies 3 times, it adds to the loss