Script inherits from native type 'KinematicBody2D', so it can't be instanced in object of type 'Node2D'.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By khai86

Hello, i encounter this problem while copy and paste a code that i found in here,
please take note i just started godot not even within 24 hour since this question is posted, what i am trying to dulpicate is a feature that will make the obeject (player) move to any location that is touch in the screen,

again here are the error:
Script inherits from native type ‘KinematicBody2D’, so it can’t be instanced in object of type ‘Node2D’.

and here are the script :

extends KinematicBody2D

const GRAVITY = 20

const MAX_SPEED = 200
const JUMP_HEIGHT = -500
const UP = Vector2(0,-1)

var motion = Vector2()

enum STATES {

onready var state = STATES.Idle

func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
var local_event = make_input_local(event)

		if local_event.position.x > 20: #and local_event.position.y > -50:
			state = STATES.MoveRight
		elif local_event.position.x < -20: #and local_event.position.y > -50:
			state = STATES.MoveLeft
		elif round(local_event.position.y) in range(-400, -20):
			state = STATES.Jump
		state = STATES.Idle

func _physics_process(delta):
motion.y += GRAVITY
var friction = false
match state:
motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
$Sprite.flip_h = false
motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
$Sprite.flip_h = true
friction = true
if is_on_floor():
motion.y = JUMP_HEIGHT
if friction == true:
motion.x = lerp(motion.x, 0, 0.2)
if motion.y < 0:
if friction == true:
motion.x = lerp(motion.x, 0, 0.1)

motion = move_and_slide(motion, UP)

Thank you for helping

:bust_in_silhouette: Reply From: kidscancode

You seem to have attached this script to a node that isn’t a KinematicBody2D.

The script begins with extends KinematicBody2D so it can’t be attached to a Node2D.

Hye thanks for the fast reply,

i have now move the script and attach it with KinematicBody2D now a new error came up

error(21,1): Indented block expected after declaration of “input”

here is the full script ( not sure if the forum set the script correctly so i paste it to another site)

Script Link

khai86 | 2021-07-30 20:13

That copy-and-paste has completely destroyed all the necessary code formatting. GDScript requires indentation to indicate code blocks.

func _ready():
    print("hello world")


func _ready():
print("hello world")

kidscancode | 2021-07-30 20:18

oh my… well i will make a proper question from beginning then, how can i delete this question

khai86 | 2021-07-30 20:22