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:
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;
FlingRandomPlayer();
3 comments
Thank you very much for your help! I'm going to give this script a shot. Basically what happens when the script is run is that it flings a random player instead of all of the players. Thanks for your response!
Oh, in that case, I'll put edit my answer and add a new bit of code for you to use. Have a look!
Don't forget to mark this question as answered, bud! Have a nice day! c;