One object being held at a time

I’m using a hold system, and I’m wondering how to make it so the player can only hold one block at once. How would I achieve this? (A event is fired so I’m not sure if that’d help)

local ClickDetector = script.Parent.ProximityPrompt
local RS = game:GetService("ReplicatedStorage")
local PS = game:GetService("Players")
local HoldEvent = RS:WaitForChild("HoldEvent")

ClickDetector.Triggered:Connect(function(Player)
	local LeftArm = Player.Character:WaitForChild("Left Arm")
	local Humanoid = Player.Character:WaitForChild("Humanoid")
	local Weld = Instance.new("WeldConstraint")
	local leftarmpos = nil
	script.Parent.CFrame = LeftArm.CFrame + Vector3.new(0, -1.5, 0)
	ClickDetector.MaxActivationDistance = 0
	Weld.Parent = script.Parent
	Weld.Part0 = script.Parent
	Weld.Part1 = LeftArm
	script.Parent.Anchored = false
	script.Parent.CanCollide = false
	HoldEvent:FireClient(Player)
	HoldEvent.OnServerEvent:Connect(function()
		Weld:Destroy()
		script.Parent.CanCollide = true
		HoldTrack:Stop()
		wait(10)
	end)
end)

HoldEvent = RS:WaitForChild("HoldEvent")

Possibly you could add a value to the player object, such as IntValue. Then in the click detector triggered event add 1 to that value. Check if Player.MaxItemsHeld.Value <= 0 then allow the player to pick up the item. Set MaxItemsHeld.Value back to 0 when the player lets go.

I used IntValue in this case because it could allow for the player to hold more items if you wish for that. Otherwise you could just use BoolValue to achieve a single pick up. i.e., true if something is held, false if nothing is held

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.