Server crashing when I try to make an entity pathfind

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Gufler

Member
Nov 28, 2020
1
0
1
I'm new to skript so I'm trying some things, and I'm trying to make all pigs pathfind to the player, but every time I spawn a pig my server crashes
Code:
on spawn of pig:
        while entity is alive:
        loop players in radius 10 of the entity:
                broadcast "%loop-player%"
                make event-entity pathfind to location of loop-player with speed 1
                exit loop
idk if this "CODE" thing will work I'm sorry

edit:
I got my code to work, but I want to make all pigs follow me but just the last spawned does
Code:
every 1 tick:
    loop all pigs:
        set {_pig} to loop-entity
    loop all players:
        set {_player} to loop-player
    make {_pig} pathfind to location of {_player} with speed 1.3
 
Last edited:
the problem with your first code is that it loops so fast that it crashes the server
I recommend adding a wait trigger to reduce lag
Code:
on spawn of pig:
        while event-entity is alive:
                loop players in radius 10 of event-entity:
                        broadcast "%loop-player%"
                        make event-entity pathfind to location of loop-player with speed 1
                        exit loop
                wait 1 second
 
Status
Not open for further replies.