I need help with a random tool giver script

Hello developers!
am trying to make a random tool giver when a map is selected.So the players get a random tool when the game selects a map for them.

Can anyone help me?

This is my try:

"'local LobbyMinutes = 0
local LobbySeconds = 1

local GameMinutes = 1
local GameSeconds = 59

local Items = game.ServerStorage.Items:GetChildren()

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local TimerValues = ReplicatedStorage:WaitForChild(“TimerValues”)
local gameTimer = TimerValues.GameTimer
local lobbyTimer = TimerValues.LobbyTimer

local TweenService = game:GetService(“TweenService”)
local FadeInfo = TweenInfo.new(1.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

function teleportPlayers(RP,SpawnPart)
if RP ~= nil then
if SpawnPart ~= nil then
RP.CFrame = SpawnPart.CFrame
end
end
end

while true do
lobbyTimer.Minutes.Value = LobbyMinutes
lobbyTimer.Seconds.Value = LobbySeconds

repeat wait(1)
	if lobbyTimer.Seconds.Value > 0 then
		lobbyTimer.Seconds.Value -= 1
	else
		if lobbyTimer.Minutes.Value > 0 then
			lobbyTimer.Minutes.Value -= 1
			lobbyTimer.Seconds.Value = 59
		end
	end
until lobbyTimer.Minutes.Value == 0 and lobbyTimer.Seconds.Value == 0

local mapHolder = game:GetService("ServerStorage").MapHolder
local Children = mapHolder:GetChildren()
local Index = math.random(1,#Children)
local randomInt = Children[Index]

local finalMap = mapHolder:FindFirstChild(randomInt.Name):Clone()   
finalMap.Parent = workspace

for _, LocalPlayer in pairs(game:GetService("Players"):GetChildren()) do
	if LocalPlayer.Character then
		if LocalPlayer:FindFirstChild('PlayerGui') and LocalPlayer.Character:FindFirstChild('HumanoidRootPart') then
			local GUI = Instance.new("ScreenGui")
			GUI.Name = "Fade"
			GUI.Parent = LocalPlayer.PlayerGui
			GUI.ResetOnSpawn = false
			GUI.IgnoreGuiInset = true
			GUI.Enabled = true

			local NewValue = Instance.new("BoolValue")
			NewValue.Name = "Ingame"
			NewValue.Parent = LocalPlayer.Character
			NewValue.Value = false

			local Frame = Instance.new("Frame")
			Frame.Parent = GUI 
			Frame.BackgroundTransparency = 1
			Frame.BackgroundColor3 = Color3.fromRGB(0,0,0)
			Frame.Visible = true
			Frame.Size = UDim2.new(1,0,1,0)
			Frame.Position = UDim2.new(0,0,0,0)

			local TweenIn = TweenService:Create(Frame,FadeInfo,{BackgroundTransparency = 0})
			TweenIn:Play()

			TweenIn.Completed:Connect(function()
				teleportPlayers(LocalPlayer.Character.HumanoidRootPart,finalMap:FindFirstChild('SpawnPart'))
				wait(2)
				local TweenOut = TweenService:Create(Frame,FadeInfo,{BackgroundTransparency = 1})
				TweenOut:Play()

				TweenOut.Completed:Connect(function()
					GUI:Destroy()
				end)
			end)
		end
	end
end

wait(1.6 + 2)

gameTimer.Minutes.Value = GameMinutes
gameTimer.Seconds.Value = GameSeconds

repeat wait(1)
	if gameTimer.Seconds.Value > 0 then
		gameTimer.Seconds.Value -= 1
	else
		if gameTimer.Minutes.Value > 0 then
			gameTimer.Minutes.Value -= 1
			gameTimer.Seconds.Value = 59
		end
		local RandomItem = Items[math.random(1, #Items)]
		RandomItem:Clone().Parent = Children.Backpack
	end
until gameTimer.Minutes.Value == 0 and gameTimer.Seconds.Value == 0

for _, LocalPlayer in pairs(game:GetService("Players"):GetChildren()) do
	if LocalPlayer.Character then
		if LocalPlayer:FindFirstChild('PlayerGui') and LocalPlayer.Character:FindFirstChild('Ingame') then
			local GUI = Instance.new("ScreenGui")
			GUI.Name = "Fade"
			GUI.Parent = LocalPlayer.PlayerGui
			GUI.ResetOnSpawn = false
			GUI.IgnoreGuiInset = true
			GUI.Enabled = true

			local Frame = Instance.new("Frame")
			Frame.Parent = GUI 
			Frame.BackgroundTransparency = 1
			Frame.BackgroundColor3 = Color3.fromRGB(0,0,0)
			Frame.Visible = true
			Frame.Size = UDim2.new(1,0,1,0)
			Frame.Position = UDim2.new(0,0,0,0)

			local TweenIn = TweenService:Create(Frame,FadeInfo,{BackgroundTransparency = 0})
			TweenIn:Play()

			TweenIn.Completed:Connect(function()
				LocalPlayer:LoadCharacter()
				wait(2)
				local TweenOut = TweenService:Create(Frame,FadeInfo,{BackgroundTransparency = 1})
				TweenOut:Play()

				TweenOut.Completed:Connect(function()
					GUI:Destroy()
				end)
			end)
		end
	end
end

wait(1.6)
finalMap:Destroy()
wait(2)

end’"
lua

1 Like

Essentially when you teleport a player, you take a random tool from replicated storage:
(after cloning set parent to v) cant do it on my current phone iphone5s its all glitched :frowning:
for _,v in ipairs(players) do
local choosen_item = Items:GetChildren()[math.random(#Items:GetChildren())

choosen_item:Clone()

So do I put this into the same place that I wrote for the giver command?

Personally, i would use math.random to make a random number obviously
Then id wanna get all the children of the folder that have all the tools
Id loop all the players using for i,v in loop, make a random number, then give them the player

Now i dont really know how to find the weapon but this is just a vague idea on how to do it
Hope this helps

In the function teleportplayers you do:
1 - check if player is alive

then:

function Teleportplayers(){
-- You teleport players first (ID Recommend making a list which checks players in game)
local destination = CFrame.new(0,0,0) -- Your spawnlocation here

for _,v in ipairs(players) do

v.Character:WaitForChild("HumanoidRootPart",1).CFrame = destination

local choosen_item = Items:GetChildren()[math.random(#Items:GetChildren())
choosen_item:Clone()

choosen_item.Parent = v.Backpack

end

Can you send me the script because I didn’t understand

Okay wait imma go try it in studio

The intire script doesn’t work with this

Whats the problem in the script? Any errors?

its not working got anything else?

can you write your script inside my script so I can see how do I do it?

bro we are literally trying to do the same thing, im using the same script as you lol.

local Weapons = game:GetService(ReplicatedStorage).ToolsToGive:GetChildren()|
local randomWeapons = Weapons[math.random(1, #Weapons)]:Clone()|
randomWeapons.Parent = LocalPlayer.Backpack|