Hi, I'm having trouble with calling a function from another script. Code is below:

The player script is attempting to call the TakeDamage() function from the SlimeAI script.

Here is the player script:

GameObject slimeScript = GameObject.Find(“Slime”).slimeAIScript.TakeDamage();

Here is the slimeAI script:

public void TakeDamage()
{
health -= attackDamage; //attackDamage float value is assigned above;
}

Looks like you’re referencing “.slimeAIScript” as a variable. You would want to get the component.
Basically you don’t have a variable assigned to the script already.
Also using GameObject.Find is pretty expensive so it’s best to find alternatives.

Either way, ignoring that the Find function is expensive, you would need to get the game object and then call ".getComponent().

So something like this:

SlimeAI slimeScript;

Public void Start()
{
slimeScript = GameObject.Find("Slime").getComponent<SlimeAI>();
} 

And then when you’re ready to use it, call this:

slimeScript.TakeDamage();