This script is within a button which will give you two weapons on click, but there is a problem. I keep getting this error “Expected ‘end’ (to close ‘function’ at line 8), got eof” and I’m not sure how to fix it. I have tried adding more ends and putting some ends in different places, but none of them have deemed effective.
--Insurgents
--Variables
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local primary = ReplicatedStorage.Guns:FindFirstChild("UMP45")
local secondary = ReplicatedStorage.Guns:FindFirstChild("RPG-7")
--Script
script.Parent.MouseButton1Click:connect(function()
if primary and not plr.StarterPack:FindFirstChild(primary) then
primary:Clone().Parent = plr.StarterGear
primary:Clone().Parent = plr.Backpack
if secondary and not plr.StarterPack:FindFirstChild(secondary) then
secondary:Clone().Parent = plr.StarterGear
secondary:Clone().Parent = plr.Backpack
end
plr.TeamColor = BrickColor.new("Navy blue")
game.Players.LocalPlayer.Character.Humanoid.Health = 0
script.Parent.Parent.Parent.Parent.Sidebar.Visible = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end
--Insurgents
--Variables
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local primary = ReplicatedStorage.Guns:FindFirstChild("UMP45")
local secondary = ReplicatedStorage.Guns:FindFirstChild("RPG-7")
--Script
script.Parent.MouseButton1Click:Connect(function()
if primary and not plr.StarterPack:FindFirstChild(primary) then
primary:Clone().Parent = plr.StarterGear
primary:Clone().Parent = plr.Backpack
if secondary and not plr.StarterPack:FindFirstChild(secondary) then
secondary:Clone().Parent = plr.StarterGear
secondary:Clone().Parent = plr.Backpack
end
plr.TeamColor = BrickColor.new("Navy blue")
game.Players.LocalPlayer.Character.Humanoid.Health = 0
script.Parent.Parent.Parent.Parent.Sidebar.Visible = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
--Variables
local plr = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Guns = ReplicatedStorage:WaitForChild("Guns");
local primary = Guns:FindFirstChild("UMP45")
local secondary = Guns:FindFirstChild("RPG-7")
--Script
script.Parent.MouseButton1Click:Connect(function()
if primary and not plr.Backpack:FindFirstChild(primary.Name) then
primary:Clone().Parent = plr.Backpack
end
if secondary and not plr.Backpack:FindFirstChild(secondary.Name) then
secondary:Clone().Parent = plr.Backpack
end
plr.TeamColor = BrickColor.new("Navy blue")
game.Players.LocalPlayer.Character.Humanoid.Health = 0
script.Parent.Parent.Parent.Parent.Sidebar.Visible = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
You forgot an end after your first if statement as well.
--Variables
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local primary = ReplicatedStorage.Guns:FindFirstChild("UMP45")
local secondary = ReplicatedStorage.Guns:FindFirstChild("RPG-7")
--Script
script.Parent.MouseButton1Click:Connect(function()
if primary and not plr.StarterPack:FindFirstChild(primary) then
primary:Clone().Parent = plr.StarterGear
primary:Clone().Parent = plr.Backpack
end
if secondary and not plr.StarterPack:FindFirstChild(secondary) then
secondary:Clone().Parent = plr.StarterGear
secondary:Clone().Parent = plr.Backpack
end
plr.TeamColor = BrickColor.new("Navy blue")
game.Players.LocalPlayer.Character.Humanoid.Health = 0
script.Parent.Parent.Parent.Parent.Sidebar.Visible = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
You should have this in a ServerScript. Or you won’t be able to access that.
Fire a RemoteEvent that clones the objects into the backpack and StarterGear.
I got frustrated and rewrote everything… not the cleanest code I’ve ever wrote but it’ll do… for this case…
StarterGear only exist if the game has gear enabled…
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 camera = workspace.CurrentCamera;
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local guns = ReplicatedStorage:WaitForChild("Guns");
local give = {"UMP45","RPG-7"};
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
for _,gun in pairs(give) do
local gun = guns:findFirstChild(gun);
if gun then
gun = gun:Clone();
gun.Parent = backpack;
end
end
end
--Insurgents
--Variables
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local primary = ReplicatedStorage.Guns:FindFirstChild("UMP45")
local secondary = ReplicatedStorage.Guns:FindFirstChild("RPG-7")
--Script
script.Parent.MouseButton1Click:connect(function()
if primary and not plr.StarterGear:FindFirstChild(primary) then
primary:Clone().Parent = plr.StarterGear
primary:Clone().Parent = plr.Backpack
end
if secondary and not plr.StarterGear:FindFirstChild(secondary) then
secondary:Clone().Parent = plr.StarterGear
secondary:Clone().Parent = plr.Backpack
end
plr.TeamColor = BrickColor.new("Navy blue")
game.Players.LocalPlayer.Character.Humanoid.Health = 0
script.Parent.Parent.Parent.Parent.Sidebar.Visible = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
Ok, your script worked fine for the most part, but I’m trying to get the guns put into the StarterGear, which I just learned is inaccessible from a local script (or the client).
I essentially gave you a StarterGear, the script checks if the players teamcolor is Navy blue, and if so, it gives them the guns, so long as this script runs every time the player spawns, it will always give them the guns.
StarterGear is accessible from local scripts, it just doesn’t exist in the player unless gear is enabled for your game.
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 camera = workspace.CurrentCamera;
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local guns = ReplicatedStorage:WaitForChild("Guns");
local give = {"UMP45","RPG-7"};
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;
for _,gun in pairs(give) do
local gun = guns:findFirstChild(gun);
if gun then
gun = gun:Clone();
gun.Parent = backpack;
end
end
end