I am making a loadout GUI. There are only two teams and each team has four unique loadouts. I am trying to make it so that when you click on the loadout, you get the specific guns entitled to that loadout, which are cloned to the StarterGear.
Basically, when you press the button, it should fire to the remote event in ReplicatedStorage which is connected to the Demolitions script inside ServerScriptStorage, which should clone to the StarterGear, but I’m unaware to how to do that. I also think that I used a few wrong references.
Also, I keep getting this error, “ServerScriptService.Loadout.Demolitions:6: attempt to index nil with ‘StarterGear’”.
In the Loadout script inside the GUI, I have this code.
--Variables
local players = game:GetService("Players");
local player = players.LocalPlayer;
repeat wait(0.01) until player.Character;
local character = player.Character;
local backpack = player:WaitForChild("Backpack");
local humanoid = character:WaitForChild("Humanoid");
local button = script.Parent;
local sidebar = script.Parent.Parent.Parent.Parent:WaitForChild("Sidebar");
local camscript = script.Parent.Parent.Parent.Parent:WaitForChild("CameraOnJoin")
local camera = workspace.CurrentCamera;
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local guns = ReplicatedStorage:WaitForChild("Guns");
local give = {"UMP45","RPG-7"};
local demolitions = game.ReplicatedStorage.Loadout:WaitForChild("Demolitions")
if player.TeamColor ~= BrickColor.new("Navy blue") then
script.Parent.MouseButton1Click:Connect(function()
player.TeamColor = BrickColor.new("Navy blue");
sidebar.Visible = false;
camera.CameraType = Enum.CameraType.Custom;
humanoid.Health = 0;
end);
else
sidebar.Visible = false;
camscript.Disabled = true;
end
script.Parent.MouseButton1Click:Connect(function()
demolitions:FireServer()
print("Fired")
end)
In the Demoltions script in ServerScript Storage, I have this code.
--Variables
local demolitions = game.ReplicatedStorage.Loadout:FindFirstChild("Demolitions")
local give = {"UMP45","RPG-7"};
local guns = game.ReplicatedStorage:FindFirstChild("Guns")
local plr = game.Players.LocalPlayer
local starterGear = plr.StarterGear
local primary = guns:FindFirstChild("UMP45")
local secondary = guns:FindFirstChild("RPG-7")
print("Initiating")
demolitions.OnServerEvent:Connect(function()
primary:Clone()
primary.Parent = starterGear
print("Cloned Primary")
secondary:Clone()
secondary.Parent = starterGear
print("Cloned Secondary")
end)
I would love to hear your feedback on how to make this work and to maybe polish it up a little.