Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Team Tool Giver (With Random Tools) Any Help?

Asked by 9 years ago

-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

Log in to vote
0
Answered by
Marios2 360 Moderation Voter
9 years ago

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)
0
Thanks for the help ill check it out and see if all goes well. CarterTheHippo 120 — 9y
0
So far its not working, saying it needs another end ill edit the script and get back to you CarterTheHippo 120 — 9y
0
You're right i forgot one end, i added it back - It's at line 10. It should work now. Marios2 360 — 9y
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. CarterTheHippo 120 — 9y
View all comments (9 more)
0
That is called Brute-forcing in our language. Anyway i re-edited my script so it should work now. Marios2 360 — 9y
0
Ok, ill check it out CarterTheHippo 120 — 9y
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? CarterTheHippo 120 — 9y
0
Yes, but that is off the topic of this question. Marios2 360 — 9y
0
If you want I can just ask another question with that topic. CarterTheHippo 120 — 9y
0
Actually, it isn't - my mistake. Another, and hopefully final, edit. Marios2 360 — 9y
0
Still doesnt work... CarterTheHippo 120 — 9y
0
Can't help then. Marios2 360 — 9y
0
ok ill ask someone else but ill accept your answer because you tired CarterTheHippo 120 — 9y
Ad

Answer this question