Here's what i've tried so far:
for _,P in pairs(game.Players:GetPlayers()) do if P.Character then local t=P.Character:FindFirstChild("Humanoid") if t then t.Parent.Torso.Velocity = Vector3.new(300,5,25) end end end
but this only seems to fling one player. Could somebody possibly modify it to make it fling all the players in the server instead of just one? I am stumped here and I have been working on it for almost 2 weeks!
Thanks for your help!
Hey JSAcela,
There isn't any immediately noticeable problem with your code, but I have noted that you do not check to make sure that the Torso of the current player actually exists. If the current player does not have a Torso, your code will immediately break. Try something like this:
for i, player in pairs(game.Players:GetPlayers()) do if player.Character then local torso = player.Character:FindFirstChild("Torso"); if (torso) then torso.Velocity = Vector3.new(300,5,25); end; end; end;
I did notice how you didn't do a very good job indenting and using descriptive variable names. I highly recommend reading this very informative and useful blog post by NoahWillCode:
https://scriptinghelpers.org/blog/clean-and-tidy
Have a nice day, JSAcela, and best of luck with your project!
Cheers,
tkcmdr
Edit:
Here is a new bit of code that will fling a random player:
-- Returns a list of characters with a torso. local function GetCharacters() local characters = {}; for i, player in pairs(game.Players:GetPlayers()) do local isValidCharacter = ( player.Character and player.Character:FindFirstChild("Torso") ); if (isValidCharacter) then table.insert(characters, player.Character); end; end; return characters; end; local function FlingRandomPlayer() local characters = GetCharacters(); local victim = characters[math.random(1, #characters)]; if (victim) then victim.Torso.Velocity = Vector3.new(300,5,25); end; end; -- ... -- Fling a random player. FlingRandomPlayer();