How to make the arrow disappear when i claim a tool

  • I would like to make the arrow appear when the player touches the door hitbox,
  • and I would like to make the arrow disappear when the player claims the card,
  • and also, make the arrow disappear if the player dies or leaves. and he must then touch the door hitbox again to make the arrow reappear

I have searched everywhere and I have no idea how to do something like that, can you show me and explain it to me please, I am using this system to learn how to destroy and reappear a part when the player claim a part or a tool with a verification.

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local ArrowModel = ReplicatedStorage:WaitForChild("ArrowModel")
local target = workspace.Game.System.door.KeycardDoor.hitbox
local character = player.Character or player.CharacterAdded:Wait()
local card = workspace.Game.System.door["Weapon Spawner!"].KEYCARD

local Arrow = ArrowModel:Clone()
Arrow.Parent = player.Character

RunService.Heartbeat:Connect(function()
	Arrow.PrimaryPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, target.Position)
end)



image
image

Solution :

change tool and the target.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() -- Or you can just use script.Parent bc that a character script

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ArrowModel = ReplicatedStorage:WaitForChild("ArrowModel")
local target = workspace.Game.System.door.Spawner.WeaponSpawner
local hitbox = game.Workspace:WaitForChild("Game"):WaitForChild("System"):WaitForChild("door"):WaitForChild("KeycardDoor"):WaitForChild("hitbox")

local Arrow = ArrowModel:Clone()
Arrow.Parent = player.Character

local function checkToolInBackpack(toolName)
	if player.Backpack:FindFirstChild(toolName) or character:FindFirstChild(toolName) then
		return true
	end
	
	return false
end

hitbox.Touched:Connect(function(otherPart)
	if otherPart:IsDescendantOf(character) then -- If touched part is a local player character
		if not checkToolInBackpack("KEYCARD") then -- Change name of tool
			Arrow.Arrow.Transparency = 0
			
			while true do
				Arrow.PrimaryPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, target.Position)
				RunService.Heartbeat:Wait()
				if checkToolInBackpack("KEYCARD") then
					Arrow:Destroy()
					break
				end
			end
		end
	end
end)

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