You are changing questions. You asked what was the purpose of the sun. Now you are changing it to why does the sun exist. Those are two different questions.
The role the sun plays is it's purpose. The purpose of the sun is to provide heat, light, other forms of radiation, gravity fields and create elements beyond hydrogen and helium.
Why the sun exists is because hydrogen and helium naturally and logically complexified into structures like stars and galaxies. It is entirely predictable according to the laws of nature.