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

How to make a wrong line into a correct line, tool equipped, and text[parent.name] == true wise?

local clearance = {
	["Card-Omni"] = true, 
	["Card-L5"] = true, 
	["Card-L4"] = true,
	["Card-L3"] = true,
	["Card-L2"] = false,
	["Card-L1"] = false
}

and

local Debounce = false
script.Parent.Event.OnServerEvent:connect(function(Player)
    local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
    if Mag <= script.Parent.Range.Value then
	if tool.Equipped:connect() and clearance[script.Parent.Name] == true then
	if not Debounce then
		Debounce = true

Everything below Debounce = true is text for the script that you don't need to look at. What I do want to focus on however is

if tool.Equipped:connect() and clearance[script.Parent.Name] == true then

I know this line is incorrect in all levels but I don't know the scripting on how to make tool.Equipped:connect(), into "if a tool from clearance is equipped on player" and clearance[script.Parent.Name] == true then, into "if tool equipped has clearance that's true." I don't know anything about scripting and I'm lucky I've made it this far. The original purpose of the script which makes you stand near a door and press "e" to open and close it does works except now I'm trying to make it into a keycard door where you equip your keycard and press "e" instead. Due to the fact that the line is incorrect entirely, the door cannot work as a keycard door.

1 comment

0

you can shorten if whatever == true to just if whatever

1 answer

You'd need to use a variable for it, toggling it when they equip and unequip it. An example of this would be:

local tool1 = workspace.something; -- some tools
local tool2 = workspace.somethingelse; -- whatever
local toolsEquipped = { -- make a list with tools being indexes and bool values
	tool1 = false;
	tool2 = false; -- start both as false because they're not equipped yet
}

for i,_ in pairs(toolsEquipped) do -- for each tool
	i.Equipped:Connect(function() -- when it's equipped set the value in the list to true
		toolsEquipped[i] = true;
	end)
	i.Unequipped:Connect(function()
		toolsEquipped[i] = false; -- when it's unequipped set the value in the list to false
	end)
end

In this particular example, you can check whether something's currently equipped by checking toolsEquipped[referenceToTool], but you can always just set a normal variable and check something along the lines of tool1Equipped.

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