So i’m trying to make a mobile crosshair that detects when a player pulls out a certain weapon.
I’m getting the error "Expected ‘)’ to close ‘(’ at line 13), got ‘end’
I’m probably just an idiot but I don’t see what I have to do.
local CROSSHAIR = "rbxassetid://81623697"
local MobileCrosshair = player.PlayerGui.MobileCrosshair
local knife = script.Parent.Parent.Backpack:FindFirstChild("Knife")
local revolver = script.Parent.Parent.Backpack:FindFirstChild("Revolver")
--mobile detection
local inputService = game:GetService("UserInputService")
if inputService.TouchEnabled or inputService.KeyboardEnabled
then if InputService.TouchEnabled then
if knife.Equipped:Connect(function(mouse)
MobileCrosshair.Visible = true
if knife == nil then MobileCrosshair.Visible = false
else if revolver.Equipped:Connect(function(mouse)
MobileCrosshair.Visible = true
if revolver == nil then MobileCrosshair.Visible = false
end
end
end)
So first of all, the formatting of this is really bad, and consider organizing your code better. Here is the completed script:
local CROSSHAIR = "rbxassetid://81623697"
local MobileCrosshair = game.StarterGui.MobileCrosshair
local knife = script.Parent.Parent.Backpack:FindFirstChild("Knife")
local revolver = script.Parent.Parent.Backpack:FindFirstChild("Revolver")
--mobile detection
local inputService = game:GetService("UserInputService")
if inputService.TouchEnabled or inputService.KeyboardEnabled
then if InputService.TouchEnabled then
if knife.Equipped:Connect(function(mouse)
player.PlayerGui.MobileCrosshair.Visible = true
if knife == nil then player.PlayerGui.MobileCrosshair.Visible = false
else if revolver.Equipped:Connect(function(mouse)
player.PlayerGui.MobileCrosshair.Visible = true
if revolver == nil then player.PlayerGui.MobileCrosshair.Visible = false
end
end)
then
end
end
end)
then
-- do stuff
end
end
end
Basically you did not have enough ends, that is because your code is not organized.
Now it says expected ‘end’ (to close ‘then’ at line 8), got
local MobileCrosshair = game.StarterGui.MobileCrosshair
local knife = script.Parent.Parent.Backpack:FindFirstChild("Knife")
local revolver = script.Parent.Parent.Backpack:FindFirstChild("Revolver")
--mobile detection
local inputService = game:GetService("UserInputService")
if inputService.TouchEnabled or inputService.KeyboardEnabled
then if InputService.TouchEnabled then
if knife.Equipped:Connect(function(mouse)
player.PlayerGui.MobileCrosshair.Visible = true
if knife == nil then player.PlayerGui.MobileCrosshair.Visible = false
else if revolver.Equipped:Connect(function(mouse)
player.PlayerGui.MobileCrosshair.Visible = true
if revolver == nil then player.PlayerGui.MobileCrosshair.Visible = false
end
end)
then
end
end
end)
then
end
Try closing each dropdown one by one. That usually helps me when I have this issue. You can collapse a function by pressing the down arrow on the left side of the script window. Make sure that each function is ended by the corresponding end that you want it to close. Hope this helps!
local MobileCrosshair = game.StarterGui.MobileCrosshair
local knife = script.Parent.Parent.Backpack:FindFirstChild("Knife")
local revolver = script.Parent.Parent.Backpack:FindFirstChild("Revolver")
--mobile detection
local inputService = game:GetService("UserInputService")
if inputService.TouchEnabled or inputService.KeyboardEnabled then
if inputService.TouchEnabled then
knife.Equipped:Connect(function(mouse)
player.PlayerGui.MobileCrosshair.Visible = true
if knife == nil then
player.PlayerGui.MobileCrosshair.Visible = false
end
revolver.Equipped:Connect(function(mouse)
player.PlayerGui.MobileCrosshair.Visible = true
if revolver == nil then
player.PlayerGui.MobileCrosshair.Visible = false
end
end)
end)
end
end
Here’s the code. I want to remind you to keep your code organized. I found many errors other than just the end error, like the misuse of then. There was also some capitalization errors (LUA is a Case Sensitive coding language). Finally, I’m not sure if you did it already, but the player variable is not defined in the code. What that means is that you have to create a variable that is equal to the player.