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

Team Tool Giver (With Random Tools) Any Help?

-This script already doesnt work... But what I am trying to make it able to do is Give the Bright Red Team A knife from ServerStorage And Bright Blue team a chance at getting A pistol Or A sniper. (50/50 Chance) NOT looking for a script to be activated on touch or clicked.

-Scrip has to have the capability to be able be pasted into workspace from serverstorage(Which i can handle) and give the players on teams red and blue their tools.

This is the script:

local Knife = game.ServerStorage.Cane
local Pistol = game.ServerStorage.Pistol
local Sniper = game.ServerStorage.Sniper

game.Players.PlayerAdded:connect(function(player) 
    if player.TeamColor == BrickColor.Red then 
	Knife:Clone().Parent = player.StarterGear
	
elseif player.TeamColor == BrickColor.Blue then
	        Pistol:Clone().Parent = player.StarterGear
end
end)

-However I want the tool to be able to be lost when they die.

I tried this recently but still did not work...

local Knife = game.ServerStorage.Knife
local Pistol = game.ServerStorage.Pistol
local Sniper = game.ServerStorage.Sniper
	 
for _, player in pairs(game.Players:GetPlayers()) do
if player.TeamColor == BrickColor.Red then
Knife:Clone().Parent = player.Backpack
elseif player.TeamColor == BrickColor.Blue then
local rnd = math.random() --An empty math.random returns 0 or 1
if rnd == 0 then Pistol:Clone().Parent = player.Backpack else 
Sniper:Clone().Parent = player.Backpack end
end
end

1 answer

✓ Accepted answer

All you need here is a math.random variable to then choose Pistol or sniper.

And if you want the tool to dissapear when a player dies, put it in Backpack instead.

local Knife = game.ServerStorage.Cane
local Pistol = game.ServerStorage.Pistol
local Sniper = game.ServerStorage.Sniper

game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player.Character --Once the player is actually able to play...
    if player.TeamColor == BrickColor.Red then 
    Knife:Clone().Parent = player.Backpack
elseif player.TeamColor == BrickColor.Blue then
    local rnd = math.random() --An empty math.random returns 0 or 1
    if rnd == 0 then Pistol:Clone().Parent = player.Backpack else Sniper:Clone().Parent = player.Backpack end
end
end)

13 comments

0

Thanks for the help ill check it out and see if all goes well.

0

So far its not working, saying it needs another end ill edit the script and get back to you

0

You're right i forgot one end, i added it back - It's at line 10. It should work now.

0

stil didnt work, what I am doing if having the script also copy and pasted into workspace, hoping it will find the blue and red team players and give them there tools.

0

That is called Brute-forcing in our language. Anyway i re-edited my script so it should work now.

0

Ok, ill check it out

0

Sadly still not working, maybe its because the script is working on players that just joined? Would it be possible to re-route the script towards players already in the game/already on the team?

0

Yes, but that is off the topic of this question.

0

If you want I can just ask another question with that topic.

0

Actually, it isn't - my mistake. Another, and hopefully final, edit.

0

Still doesnt work...

0

Can't help then.

0

ok ill ask someone else but ill accept your answer because you tired

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