Ad
Log in to vote
0

How do I choose one player and give them a sword?

Asked by 8 years ago

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.

1 answer

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
8 years ago

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)
0
Thanks, but how do I make it show the players name it picked in a message? FamousDoge 0 — 8y
0
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. Ekkoh 635 — 8y
Ad

Answer this question