How can I make my player movement static from another script?

Here’s my question:

Question

I have a weight in a gym game that whenever the player touches it it stays in the weight position and makes his player movement static.
want to make my player speed to 0 but it doesn’t work. Now I have another script that wants to make the player speed 300 but it doesn’t work even when I check with a print that tells me it has changed the player speed but it doesn’t actually change it. I have tried and searched for dozens of hours and didn’t find anything… How can I do it? The weight is an Area2D by the way.

I am using the normal built-in move and slide script for the movement too. Any tips?

perhaps elaborate more on what you are trying to make?
from what i read, it’s basically you want other sprite animation to stay as is now whenever you are picking/pressing/button down a certain object (weight)?

Hi can you post your code?

Ok so basically here’s my movement code:

extends CharacterBody2D

@export var speed = 400

func get_input():
	var input_direction = Input.get_vector("left", "right", "up", "down")
	velocity = input_direction * speed

func _physics_process(delta):
	get_input()
	move_and_slide()

It’s really basic. Then I also have a script for the Area2D object but I have no idea how to make it work. Can you help?

Btw my idea is to make the weight disappear and then set the speed variable to 0 so he doesn’t move and then move it to the area2D position and then play a sprite animation that I already made.

Weight means the weight that you lift in the gym like the object you lift. And it’s not the sprite animation it’s the speed variable for this code:

extends CharacterBody2D

@export var speed = 400

func get_input():
	var input_direction = Input.get_vector("left", "right", "up", "down")
	velocity = input_direction * speed

func _physics_process(delta):
	get_input()
	move_and_slide()

You would just have to touch it and then you are lifting the weight.

wont changing speed variable make it stop moving?
from the code snippet, it should stop the character movement

I wouldn’t set the speed to 0. I would check if the player is touching the weight and then set the velocity to zero. If you set the speed to zero you also have to set it back as well.

Here’s my code for when the player touches a coin…might help:

func _on_body_entered(body):
	if body.name == ("player"):
		print("COIN")
		global.score += 10
		global.coins += 1
		print (global.score)
		print (global.coins)
		$AnimatedSprite2D.visible = false
		$CollisionShape2D.set_deferred("disabled",true)
		end_level()

Already tried that and it didn’t work for some reason.

I tried before and it for some reason didn’t change the variable. Everything worked fine and a simple debugging told me that the function to disable set the variable to 0 was printed so yeah it didn’t really work.