i have issue that i want to increase player jump height then player team is playing but jump height increasing even then player team is lobby. Script type is normal script and it placed in ServerScriptService
local t1 = game.Teams.Playing
local t2 = game.Teams.Lobby
local t1P = {}
local t2L = {}
local function check()
t1P = {}
t2L = {}
for i,v in pairs(game.Players:GetPlayers()) do
if v.Team == t1 then
table.insert(t1P,v)
elseif v.Team == t2 then
table.insert(t2L,v)
end
end
end
local play = coroutine.create(function()
while task.wait(5) do
check()
for i, v in pairs(t1P) do
if v.Character then
local player = game.Players:GetPlayerFromCharacter(v.Character)
local h = v.Character:FindFirstChild("Humanoid")
if h then
local counter = false
h.JumpHeight += 5
print("+5")
h.Died:Connect(function()
if player and player.Team == t2 then
h.JumpHeight = 7.2
if counter == false then
print("end reutrn")
return
end
end
end)
end
end
end
end
end)
game.Players.PlayerAdded:Connect(function()
check()
end)
coroutine.resume(play)
Wouldn’t the players be stuck in one team within this script forever with how a player is put in a team? Also maybe you can just do an if statement and table.find before the +5 on line 28 to see if the player is in the t1P list?
for seeing which team each player is in, that way it will always be up to date, otherwise you need a way to update the tables all the time which personally I wouldn’t see neccesary.
Then if you just have an if statement like
if(game.Teams.Playing:FindFirstChild(player) then -- game.Teams will always be updated from your other script, and this then checks that the player is in the "playing" team
h.JumpHeight += 5
end
local playingTeam:Team = game:GetService("Teams").Playing
local jumpHeightDefault = 7.5
local jumpHeightPlaying = jumpHeightDefault + 5
local cons = {}
local function applyChanges(character, jumpHeight:number?)
local humanoid = character:WaitForChild("Humanoid")
humanoid.JumpHeight = jumpHeight or jumpHeightPlaying
end
playingTeam.PlayerAdded:Connect(function(player)
if player.Character then
applyChanges(player.Character)
end
cons[player] = player.CharacterAdded:Connect(applyChanges)
end)
playingTeam.PlayerRemoved:Connect(function(player)
if cons[player] then
cons[player]:Disconnect()
cons[player] = nil
if player.Character then
applyChanges(player.Character, jumpHeightDefault)
end
end
end)
Altough i’d just change in the code where you assign the team to the player
its not looped its adds only 1 time not every 5 sec(need to loop if player team == playing but if player team == lobby then not loop and set back to original jumpheight)
local playingTeam:Team = game:GetService("Teams").Playing
local jumpHeightDefault = 7.5
local increase = 5
local increase_interval = 5
local cons = {}
local function setDefault(character)
local humanoid = character:WaitForChild("Humanoid")
if cons[character] then
pcall(task.cancel, cons[character])
cons[character] = nil
end
humanoid.JumpHeight = jumpHeightDefault
end
local function newCharacter(character:Model)
local humanoid = character:WaitForChild("Humanoid")
local con con = character.AncestryChanged:Connect(function()
if not character:IsDescendantOf(workspace) then
con:Disconnect()
setDefault(character)
end
end)
cons[character] = task.defer(function()
while task.wait(increase_interval) do
humanoid.JumpHeight += increase
end
end)
end
playingTeam.PlayerAdded:Connect(function(player)
if player.Character then
newCharacter(player.Character)
end
cons[player] = player.CharacterAdded:Connect(newCharacter)
end)
playingTeam.PlayerRemoved:Connect(function(player)
if cons[player] then
cons[player]:Disconnect()
cons[player] = nil
if player.Character then
setDefault(player.Character)
end
end
end)
again i have same problem jumpheight applies for only 1 player if players amount 2 or more it applies only for one, idk maybe it is error saying: DiscoverGameIcons batch load failed, loading thumbnails individually
ServerScriptService is just a very common place to have server scripts, so if you wanna handle teams it has to be Script and not LocalScript, as long as it is a server script it’s not very important where you put the script aslong as it’s in a place where it can run and ServerScriptService is a place that does well for that.
Regarding ModuleScripts then it all depends on whether it is required by a server script or by a local script, not where it is