How can I access another node from Global Script

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

How can I access player’s sprite in global script ?

Godot Version : 3.5.1

:bust_in_silhouette: Reply From: SteveSmith

In the player’s script, set the global variable to the player, e.g. Globals.player = self. Then other scripts can access it, e.g. var player = Globals.player.

I want to make a store system to my game. But I have issue in buy menu. When I pressed the buy button my character sprite doesn’t change.

My buy function

func _on_BuyCharacter_pressed():
if GlobalLevel.GlobalCoin >= 0:
	$StorePanel/CharacterBuy/Sold.visible = true
	$StorePanel/CharacterBuy/Goblin.self_modulate = Color.crimson
	$StorePanel/CharacterBuy/Locked.visible = true
	$StorePanel/CharacterBuy/Goblin/Particles2D.visible = false
	GlobalLevel.GlobalCoin = GlobalLevel.GlobalCoin - 0
	$CollectedCoins.text = str(GlobalLevel.GlobalCoin)

my Global script

var player = null

func skinChanged():
	if player:
		player.get_node("Sprite").texture = load("res://sprites/Goblin.png")

Xenapibe | 2022-12-01 09:15