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

Obby: Change team only one time ?

Asked by 8 years ago

Hello, I'm building an Obby right now and I needed a script to make a spawn change team only one time. Exemple: I succeeded the stage 1 and stepped on the checkpoint(spawn) of the stage 2 and if I try to comeback to the checkpoint of stage 1, I'll not change team because I already passed this stage earlier.

Someone gave me a script for this (Thanks to chimmihc) but there are some problems. When I'm in the spawn of the stage 1 and I go to the spawn of the stage 2 and I die, I'll spawn to the spawn of the stage 3. EDIT: I resolved the problem that I put in bold. I need to give every spawn's name a different one but this script don't match with what I want because I can comeback to every spawn that I passed.

Another thing, the script save the last spawn before I disconnected and I don't want it :( . I want when someone disconnect it reset all his progression in the Obby.

Here's the script I put in ServerScriptService :

 local saves = true -- Does it save what level they are on? If so when they join the game they go to their last level.
local playerDeadTime = 0.1 -- How long after dying players spawn





local datastore = game:GetService("DataStoreService"):GetDataStore("Stats")
game.Players.CharacterAutoLoads = false

game.Players.PlayerAdded:connect(function(player)
    local level = Instance.new("StringValue",player)
    if saves then
        local stored = datastore:GetAsync(player.userId)
        print(stored)
        if stored ~= nil then
            level.Value = stored
        else
            level.Value = "Start"
        end
    else
        level.Value = "Start"
    end
    level.Name = "SpawnLevel"
    player.CharacterAdded:connect(function(char)
        wait()
        char:MoveTo(workspace:FindFirstChild("Spawn"..level.Value,true) ~= nil and workspace:FindFirstChild("Spawn"..level.Value,true).Position  + Vector3.new(0,3,0) or Vector3.new(0,100,0))
        char:WaitForChild("Humanoid").Died:connect(function()
            delay(playerDeadTime,function() player:LoadCharacter() end)
        end)
    end)
    wait(2)
    player:LoadCharacter()
end)

game.Players.PlayerRemoving:connect(function(player)
    local level = player:FindFirstChild("SpawnLevel")
    if level then
        if saves then
            if datastore:GetAsync(player.userId) ~= nil then
                datastore:UpdateAsync(player.userId,function(old) return level.Value end)
            else
                datastore:SetAsync(player.userId,level.Value)
            end
        end
    end
end)

local function spawns()
    curse = function(p)
        for _,v in next, p:GetChildren() do
            if v:IsA("BasePart") then
                if v.Name:sub(1,5) == "Spawn" then
                    v.Touched:connect(function(hit)
                        if hit and hit.Parent then
                            local human = hit.Parent:FindFirstChild("Humanoid")
                            if human then
                                if human.Health > 0 then
                                    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                                    if player then
                                        local level = player:FindFirstChild("SpawnLevel")
                                        if level then
                                            level.Value = v.Name:sub(6)
                                        end
                                    end
                                end
                            end
                        end
                    end)
                end
            end
            curse(v)
        end
    end
    curse(workspace)
end

spawns()

game.OnClose = function()
    wait(3)
end

Thanks in advance !

2 answers

Log in to vote
0
Answered by 8 years ago

This is a part-answer, you said you didn't want their progress to save when they disconnect, the first line of the script says this:

local saves = true -- Does it save what level they are on? If so when they join the game they go to their last level.

Have you tried putting that to false?

0
@Moderance No I haven't tried but i'm sure that should work haha I resolved my problem, I found a script for team changing and I set "You need to be in Team X to go in Team X" Exemple: 1>2>3>4 = You're in Team 4 ,, 1>2>4 = You're still in Team 2 ,, 1>4>3 = You're still in Team 1 Thank you for your answer ^^ KevenUzumaki 0 — 8y
0
No problem, glad you fixed it! Moderance 30 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Problem resolved

If someone wanna know my code:

Team1 = "Team Color Here"
Team2 = "Team Color Here"

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
     local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player.TeamColor == BrickColor.new(Team1) then --If you're in this team, he detect you
     Player.TeamColor = BrickColor.new(Team2) --To change your team in this team
      end
   end
end)

You need also to place a transparent part that you uncheck CanCollide on the SpawnLocation with the same scale (Uncheck AllowTeamChangeOnTouch also)

Put the script in that transparent part.

0
I deleted the script that I have wrote in my original post. It's too much trouble with spawns. KevenUzumaki 0 — 8y

Answer this question