if i click E again after picked the Flashlight, the Flashlight gone like

Godot Version `

Godot 4.4.1 stable

Question

I got problem, if i click E again after picked the Flashlight, the Flashlight gone like in script

extends CharacterBody3D

signal interact_object

@onready var senter = $"."
@onready var raycast_cast_3d = $Head/Camera3D/hehe

var pickedObject
var is_paused = false
var flashlightOn = false

#@onready var flashlightObject = preload("res://HororTungTung/model/items/flashlight_drop.tscn")
#@onready var flashlightAHHHObject = preload("res://FlashAHHH.tscn")
#@onready var unArmed = preload("res://unarmed.tscn")
const SPEED = 5.0
const JUMP_VELOCITY = 4.5

func _ready():
	process_mode = Node.PROCESS_MODE_ALWAYS
	add_to_group("player")
	
func _input(event):
	
	#add sprint
	if event.is_action_pressed("sprint"):
		var speed
		speed = SPEED * 0.9
	else:
		var speed
		speed = SPEED * 0.5
	if event.is_action_pressed("interact") and pickedObject:
		var drop_transform = pickedObject.global_position
		pickedObject.reparent(get_tree().current_scene)
		pickedObject = null
	#if is_inside_tree() and pickedObject:
		#print("Node ini sudah berada dalam scene tree!")
	#else:
		#print("Node ini belum ada dalam scene tree.")
func _process(_delta):
	if raycast_cast_3d.is_colliding():
		var collider = raycast_cast_3d.get_collider()
		interact_object.emit(collider)
	else: interact_object.emit(null)
	if Input.is_action_just_pressed("pause"):
		is_paused = !is_paused
		get_tree().paused = is_paused
		
	if is_paused:
		Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
	else: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _physics_process(_delta):
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * _delta

	# Handle jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir := Input.get_vector("left", "right", "forward", "backward")
	var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()

func pick_up_object(object):
	#object.transform = Transform3D.IDENTITY
	object.reparent(%hand)
	object.global_transform = %hand.global_transform
	
	await get_tree().create_timer(0.1).timeout
	pickedObject = object```

Please format your code snippets as preformatted text with ``` otherwise it’s unreadable.

Where do you call pick_up_object() method from? I see it being defined, but not called anywhere. Can you share also the script that’s calling this function?

1 Like

Can you better describe what the issue is? What do you expect to happen versus what really happens?

Make sure to paste formatted code, not screenshots

I was following a tutorial on how to make a pickup flashlight, and after following the script, I tried pressing E to pick up the flashlight and when I wanted to drop it, the flashlight disappeared.