Convert Enum to a string?

Is there a way I can convert an Enum to a string?

So pretty much I’m trying to get the users platform and the platform their on make it text on TextLabel

Current code [Not Working]

script.Parent.Main.UsersPlatform.Text = "Platform: "..Enum.Platform

I hope this was enough explanation if not let me know!

I tried looking this up
Thank’s in advance :smile:

1 Like

Not tested this, but you could probably do:

platforms = {}
for key, value in pairs(Enum.Platform) do
    platforms[value] = key
end
script.Parent.Main.UsersPlatform.Text = "Platform: "..platforms[Enum.Platform]

This doesn’t work with other enums either… disregard.

1 Like

Only core scripts can get the user’s platform.

Replied to Emskipo by mistake, meant to respond to the original post.

2 Likes

Yeah I just saw that. (More Chars)

1 Like

you can use tostring()

script.Parent.Main.UsersPlatform.Text = "Platform: "..tostring(Enum.Platform)
1 Like

I’ve done this before but it seems that only corescripts can get the platform, so I suggest locally seeing if the touchpad is enabled, the gamepad is enabled ,or the keyboard is enabled, through something along the sorts of this

local mobile = game:GetService('UserInputService').TouchEnabled
local cconsole = game:GetService('UserInputService').GamepadEnabled
local desktop = game:GetService('UserInputService').KeyboardEnabled

and then perhaps using those, if youd want it to be serversided, maybe you could see which one is true, and which are false, so you can use events that fire to the server, telling the server what platform you’re on, and then managing your tags above your head from the serverscript rather than the localscript ((if its tags above the head you’re worried about))

---lets say you're checking if player is on mobile
if mobile == true then
youreventhere:FireServer("Mobile")
end

((this is quite inefficient ))

2 Likes

oop mb
you cant get the player platform from enumaration
the tittle said that convert enum to string…

getting their input is confusing since computers also have touch screens

even phones get keyboards

1 Like

True, true, i figured to post a solution ive used once before, and since someone has already helped wit hthe topic, i thought i’d somehow try to provide a secondary solution to the thing they were trying to do.

1 Like

You can use .Name

print(Enum.Platform.OSX.Name) --prints OSX
4 Likes

Thanks I’ll make this work (I understand it’s not efficent)

2 Likes

Glad you understand :slight_smile: Hope it works for you!

1 Like