Expected 'end' (to close 'function' at line 8), got <eof>

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
3 Likes
script.Parent.Parent.Parent.Parent.Sidebar.Visible = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom	

end) < you were missing that guy

5 Likes

You’re missing a parenthesis at the end.

Also connect is deprecated, use Connect

--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)
2 Likes

Ok, that actually helped solve the previous error, but now there is a new one. “Expected identifier when parsing expression, got ‘)’”

2 Likes

I believe its because you have the first parameter of “FindFirstChild” as an object rather than a string,

1 Like
--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)

edit:
yikes… I’m skipping over all of the errors

1 Like

You forgot an end after your first if statement as well. :slight_smile:


--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)
1 Like

Ooh, I forgot that one, but there is yet another error. I am now getting “StarterPack is not a valid member of Player”.

1 Like

I assume you meant to put StarterGear

1 Like

StarterPack is a service not an instance of player, I edit my reply above to fix that

2 Likes

StarterPack only exists as game.StarterPack. You need plr.BackPack (to receive right now) or plr.StarterGear (to receive every time you spawn)

And FindFirstChild will indeed fail unless you use primary.Name or “UMP45” as it expects a string, same with the secondary.

2 Likes

Yes, I meant StarterGear, but it didn’t really do much. I still got an error. "StarterGear is not a valid member of Player”.

1 Like

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)

Try that :+1:

That solution is not going to work for many reasons, we’ve discussed this already :slight_smile:

1 Like

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).

1 Like

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.

1 Like

Ok actually, it works, but is there a way to stop the Sidebar from showing up after a respawn?

1 Like

try this

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
5 Likes