So I am not an expert but here goes
if I were to do something like this I would first scan for when a player is added to the game, randomly choose their weapon and then save the choice in the server:
local players = game:GetService("Players")
local serverscripts = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
players.PlayerAdded:Connect(function(player)
local choice = Instance.new("IntValue",serverscripts)
choice.Name = player.UserId
choice.Value = math.random(1,2)
end)
then I would add a script that checks if a character has been added and give them their weapon
local players = game:GetService("Players")
local serverscripts = game:GetService("ServerScriptService")
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
local x = serverscripts:FindFirstChild(player.UserId).Value
if x == 1 then
local weapon = game.ReplicatedStorage.Weapons["Tool #1"]:clone()
weapon.Parent = player.Backpack
end
if x == 2 then
local weapon = game.ReplicatedStorage.Weapons["Tool #2"]:clone()
weapon.Parent = player.Backpack
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
player.CharacterRemoving:Connect(onCharacterRemoving)
end
players.PlayerAdded:Connect(onPlayerAdded)
Fair Warning, I have not tested these scripts!
you can get some info in here:
https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAdded
https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded
By the way, I think you may need to read this:
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
1 comment
I know you say you are bad at scripting, but why are you using two "do" in your script? I never seen this. Was that a mistake you made?