Character variables after respawn

Gotcha.

So essentially what you need the body for is the magnitude from the root part to the fruit?

To be completely honest, I am not too sure what the issue could be but instead of trying to figure out why it isn’t working I’d like to offer a little bit of a solution.

I’m thinking the issue might derive from this line:
return (plrbody.Position - a.Position).magnitude > (plrbody.Position - b.Position).magnitude

So let’s create a function that gets a new Vector3 which is equal to the player’s HRP position instead of using plrBody

local function getLocalPlayerBodyPosition() -- you can shorten this, I just like using descriptive names whenever possible
    local player = players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    return character:WaitForChild('HumanoidRootPart').Position
end

Then whenever plrbody.Position appears in your script, replace it with getLocalPlayerBodyPosition()

For example,

return (getLocalPlayerBodyPosition() - a.Position).magnitude > (getLocalPlayerBodyPosition() - b.Position).magnitude

See if that helps.

1 Like

Thanks for all the help. I’ve implemented that into my script.

I found out the problem was to do with the Tool itself - although I think there were a number of other problems to do with getting the char after death which were solved by your function. I’m not entirely sure what the exact issue was but I’m thinking it was to do with it unequipping when the char changed. I followed your advice and removed the tool entirely and placed the script into StarterPlayerScripts and it worked.

1 Like