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

How to proceed event only if player has certain tool equipped?

I have this script which is located under StarterPlayerScripts and it is a localscript, can anyone please help and add where I am supposed to write the 'if tool equipped' to proceed with the event. Thank you!

--< Services
local PlayerService = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')

--< Variables
local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()

local PlayerGui = Player:WaitForChild('PlayerGui')

local GameGui = PlayerGui:WaitForChild('GameGui')
local Text = GameGui.TextBox

local Activ = false
local Obj = nil

--< Events
UserInputService.InputBegan:Connect(function(Input)
	if Activ and Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.E and Tool.Equipped:Connect then
		Obj.Config.DetectEvent:FireServer()
	end
end)

--< Loops
while wait() do
	Obj = nil
	Activ = false
	Text.Visible = false
	for _, Door in pairs(workspace.BasementDoor:GetChildren()) do
		local mag = (Character.HumanoidRootPart.Position - Door.Center.Position).magnitude
		if mag <= Door.Config.Range.Value then
			Text.Visible = true
			Activ = true
			Obj = Door
		end
	end
end

1 answer

First of all! I don't really recommend copy pasting scripts without knowing what each part does, writing your own scripts is an even better thing. So please! Be sure to learn

For checking if a tool is equipped, there is the .Equipped event, which fires when the tool connected to that event has been equipped. More info here!

1 comment

0

Still got no idea what to do...

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