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

How would I detect if the player has an item equipped?

So, I'm making this script in which the player has to have an axe in order to interact with the tree. Here's my script:

local player = game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
while not character.Parent do
	character.AncestryChanged:Wait()
end
local Humanoid = character:WaitForChild('Humanoid')
local HRP = character:WaitForChild('HumanoidRootPart')

local mouse = player:GetMouse()

local Anim = Instance.new("Animation",script.Parent)
Anim.Name = "ChopAnim"
Anim.AnimationId = 'rbxassetid://3027147369'
local Animation = Humanoid:LoadAnimation(Anim)
local Part = script.Parent

local Tool = player.Backpack:WaitForChild('[LUMBERJACK] Axe')

game.ReplicatedStorage.PressedE.OnServerEvent:Connect(function()
	Tool.Equipped:Connect(function()
		if (HRP.Position - Part.Position).magnitude < 4.5 then
			Humanoid.WalkSpeed = 0
			Humanoid.JumpPower = 0
			Animation:Play()
		end
	end)
end)

However, It's not working. I think there is some hidden way to do it, and I do not know that.

Any help please?

4 comments

0

you can check if the tools's parent is player's character

0

you can check if the tools's parent is player's character

0

You can check it with the "equipped" function. And make a if statement if its a character then print something or something like that.

0

Nope. Doesn't work.

1 answer

You could use the equipped event to set a variable or something to true so when you want to interact it checks if equipped variable(made that variable up) is true if so then, chop it

1 comment

0

Doesn't work either.

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