I would like to include some logic in a script to avoid player.team decrease
If you are on stage 20 and you fall to stage 2 the team will change to stage 2
I have tried to make a freefall script that times the amount in time you are freefalling
then if its over a threshold say 2 sec. The script fires a remote to the server
turning off AllowTeamChangeOnTouch
This works but turns off AllowTeamChangeOnTouch for all players so is not a solution.
I have tried making the freefall script when the remote fires the server it gets the current player.team
then if the player dies (if you fell from stage 20 to 2 you would just kill the player)
it resets the player to their old team.
This is not a solution because if you reach a new checkpoint then die it will reset the team to the previous team.
So my problem is -
I have the checkpoints and teams service set up and it works well, I need to include a failsafe script
to avoid the team changing to less than what it is currently.
Try making your own obby script instead.
Then add a Stage NumberValue or IntValue and parent it to the player.
Then put this in every checkpoint, (you can also try looping through every checkpoint) If you want to loop through, add a script into ServerScriptService
script.Parent.Touched:Connect(function(hit) -- or v.Touched
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Stage.Value >= tonumber(script.Parent.Name) then -- or v.Name
print("Player stage is higher, so it did not decrease")
else
-- add stage
end
end
end)
Loop:
for i, v in pairs(game.Workspace.Checkpoints:GetChildren()) do -- or change it to your path
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Stage.Value >= tonumber(v.Name) then -- or if you don't name your checkpoints 0,1,2 etc then do: "Stage: "..tonumber(v.Name)
print("Player stage is higher, so it did not decrease")
else
-- add stage
end
end
end)
Thanks for the replies. I have made my bed with teams. I have got datastore and skip stage set up.
I have got an int number value in stage to control the skip stage.
My problem is how to avoid Goin to a lower number team than I am on.
The checkpoints use teams. There is a script looping through the checkpoints to set the value of an int. Value in the player.
I think I might have to grab the currentStage when player is failing then extract the stage no. and compare it to new Stage if it’s higher then ok. If it’s lower then revert to currentStage
Maybe you could try disabling the .AllowTeamChangeOnTouch entirely, and just connecting your own .Touched function to each checkpoint.
for _,Checkpoint in pairs(workspace.Checkpoints:GetChildren()) do -- iterate over every checkpoint (change to whatever you need)
Checkpoint.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- check if it was a player that touched the part
if Player and PlayerLevel < CheckpointLevel then -- check player's level is lower than the checkpoint
-- switch team
end
end)
end
Edit: You could also implement a basic anti-cheat with this by checking that the player isn’t skipping stages
if Player then
if PlayerLevel + 1 == CheckpointLevel then -- ensure that this is the next checkpoint
-- switch team
elseif PlayerLevel < CheckpointLevel then -- if the player's current stage isn't one underneath the current checkpoint, and their level is below the current checkpoint, that means they're skipping stages!
-- punish player (killing them would be sufficient)
end
end -- if the player's level was above the checkpoint level, then the script reaches here and nothing happens
Thanks for the suggestions but I really need to use the teams service. I have come too far down the road with teams and it’s integral. Your posts have given me some food for thought.
If I do work out a solution to the team not going lower than the current team
I will post on here
local Teams = game:GetService("Teams")
for i, v in pairs(game.Workspace.Checkpoints:GetChildren()) do -- or change it to your path
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Stage.Value >= tonumber(v.Name) then -- or if you don't name your checkpoints 0,1,2 etc then do: "Stage: "..tonumber(v.Name)
print("Player stage is higher, so it did not decrease")
else
player.Team = Teams[v.BrickColor] -- change brickcolor to team color or do something else
player.Stage.Value = tonumber(v.Name)
end
end
end)
I am stuck with Teams because I have come too far down the road with datastores, skip stages and the mechanics of the game. If I was only in the early stages of development I would have changed to the leaderstats method that was suggested.
I tried for a few hours to get @bolekinds2 script to work. I understand the logic of it and have an int number in the player for the corresponding stage no.
I couldn’t get that actual script to work even when I put in my paths and data.
All of the replies have helped in taking me to a solution to this problem.
I am not going to post scripts but will offer my solution to this. Its not really elegant it might even be considered to be a bit hacky but it works and thats the goal.
The problem falling from stage 20 to stage 2 and the teams decreasing to stage 2.
I have made under stage 20 a larger part thats invisible and cancollide off this is the Saftey Net.
In a local script in StarterPlayerCharacter I made for i,v loop that checks the folder SafteyNetCheckpoints
for all parts of the Saftey Net. When touched it fires a RemoteEvent to the server (player)
In ServerScriptServices theres a script that when the remote is recieved grabs the players currentTeam and player level int number currentLevel, when falling through the Saftey Net.
Then there is a humanoid died function, that sets the player.Team to the currentTeam and the player level to currentLevel, when the player dies.
Its maybe a bit rough but it works well
Thanks very much to all who contributed.
and I hope this helps someone with the same problem.