Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need help with this script?

local player = game.Players.LocalPlayer
y = 1
x = game.Lighting["Baton"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(x)
		y = 2
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(13/255,120/255,177/255)
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
w = game.Lighting["BillyClubRiotShield"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Q then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(w)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
r = game.Lighting["LE-AR"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(r)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
f = game.Lighting["LE-P1"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.F then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(f)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
g = game.Lighting["LE-S1"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.G then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(g)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)

this is my script now and im trying to make it that if you press / it disables this i tryed this

local player = game.Players.LocalPlayer
y = 1
key = string.lower(key)

if string.byte(key)then	
x = game.Lighting["Baton"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(x)
		y = 2
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(13/255,120/255,177/255)
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
w = game.Lighting["BillyClubRiotShield"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Q then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(w)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
r = game.Lighting["LE-AR"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(r)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
f = game.Lighting["LE-P1"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.F then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(f)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
g = game.Lighting["LE-S1"]:Clone(); 
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.G then 
		if y == 1 then
        player.Character.Humanoid:EquipTool(g)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(13/255,120/255,177/255)
		y = 2
		elseif y == 2 then
		player.Character.Humanoid:UnequipTools()
		player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3 = Color3.new(27/255,42/255,53/255)
		player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3 = Color3.new(27/255,42/255,53/255)
		y = 1
		end
    end 
end)
elseif string.byte(key) == 47 then
			
end

but this brakes the script completly so i need help

2 comments

0

Your question in title is irrelevant to your problem. You could have any code in your question and the title would fit, which is bad for anyone that stumbles across a similar problem. You didn't post your error if there is any. Do that first. If there aren't any errors, post what your code doesn't do that you wanted it to do.

0

i did

1 answer

✓ Accepted answer

The first if statement is

if string.byte(key)then

and the second one is

elseif string.byte(key) == 47 then

Since the second one can only be true if the first one is true, the second one will never happen because the first one would have to be false.

You are also creating multiple connections to InputBegan, and that is unnecessary. You can put all of them together. There also looks like a whole ton of repeated code, which can be simplified a whole ton. Here's a much shorter version. You can add whatever it is you wanted to do into the block where it checks if the key pressed was /.

local player=game.Players.LocalPlayer
local y=1
local tools={
	E=game.Lighting["Baton"]:Clone();
	Q=game.Lighting["BillyClubRiotShield"]:Clone();
	R=game.Lighting["LE-AR"]:Clone();
	F=game.Lighting["LE-P1"]:Clone();
	G=game.Lighting["LE-S1"]:Clone();
}
game:GetService("UserInputService").InputBegan:connect(function(inputObject)
	if inputObject.KeyCode.Name=="Slash"then
		
	else
		local tool=tools[inputObject.KeyCode.Name]
		if tool then
			if y==1 then
				player.Character.Humanoid:EquipTool(tool)
				y=2
				player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(13/255,120/255,177/255)
			elseif y==2 then
				player.Character.Humanoid:UnequipTools()
				player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(27/255,42/255,53/255)
				player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(27/255,42/255,53/255)
				player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(27/255,42/255,53/255)
				player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(27/255,42/255,53/255)
				player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(27/255,42/255,53/255)
				y=1
			end
		end
	end
end)

1 comment

0

I also recommend storing objects in ReplicatedStorage and not Lighting.

This discussion is preserved as it was. New answers, comments, and votes are closed.