Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

2 comments

0

Thanks, but how do I make it show the players name it picked in a message?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.