How do I create a script that chooses one random player and gives them a sword, more health and walkspeed?
Also, it needs to teleport them to a position.
How do I create a script that chooses one random player and gives them a sword, more health and walkspeed?
Also, it needs to teleport them to a position.
Here are some of the basics. You'll have to edit some things in order for it to work, but this is what it would look like for the most part.
function ChoosePlayer() -- declare function
local players = Game:GetService("Players"):GetPlayers() -- player list
local plr = players[math.random(#players)] -- random player
local hum = plr.Character:WaitForChild("Humanoid") -- declare variable for Humanoid
Game:GetService("ServerStorage"):FindFirstChild("Sword"):Clone().Parent = plr:FindFirstChild("Backpack") -- give sword
hum.MaxHealth = 200
hum.Health = (hum.Health / 100) * hum.MaxHealth -- heal the character proportionally
hum.WalkSpeed = 32 -- change walkspeed
plr.Character:MoveTo(Vector3.new(0, 0, 0)) -- teleport
return plr
end
local chosenPlr = ChoosePlayer() -- call function
local msg = Instance.new("Message", Workspace)
msg.Text = chosenPlr.Name .. " was chosen!"
Game:GetService("Debris"):AddItem(msg, 3)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Thanks, but how do I make it show the players name it picked in a message?
I made some edits to it, ChoosePlayer now returns the player that it chose so you can use the chosen player's name in a message.