Well-met Posted April 1, 2019 Share Posted April 1, 2019 Hi I'd like to lock a function behind the name of the player using it, as a means to prank my friend. Essentially the function should only trigger if the player's username is as written. I'm looking for the function to trigger when he's using the custom character himself. I tried these (separately) if UserToPlayer('namehere') then if UserToPlayer() == 'namehere' then if UserToPlayer = ('namehere') then but none of these seem to work. I tried ThePlayer but apparently this one prints random strings of numbers as a means to identify players, but it changes every game. is there some obvious thing I'm missing? Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/ Share on other sites More sharing options...
Ultroman Posted April 1, 2019 Share Posted April 1, 2019 If you just want to call a function when a certain player joins, you can do this: AddPlayerPostInit(function(inst) if inst.name == 'somename' then -- do something end end) You can check the same variable, inst.name, whenever you're doing something where you have an instance of a player. Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1172817 Share on other sites More sharing options...
Well-met Posted April 1, 2019 Author Share Posted April 1, 2019 yup it is inst.name. Thanks Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1172934 Share on other sites More sharing options...
Nicodesu Posted August 21, 2025 Share Posted August 21, 2025 On 4/2/2019 at 12:47 AM, Ultroman said: If you just want to call a function when a certain player joins, you can do this: AddPlayerPostInit(function(inst) if inst.name == 'somename' then -- do something end end) You can check the same variable, inst.name, whenever you're doing something where you have an instance of a player. Could this apply/adapt to detect other player name who playing a custom character? Like when this script put into a custom character and when a player with not the name set in the script playing this custom character, will do something or change stats? (´・ω・`) Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1832447 Share on other sites More sharing options...
Baguettes Posted August 21, 2025 Share Posted August 21, 2025 46 minutes ago, Nicodesu said: Could this apply/adapt to detect other player name who playing a custom character? Like when this script put into a custom character and when a player with not the name set in the script playing this custom character, will do something or change stats? (´・ω・`) You can use ~= instead of == to make the statement be a NOT statement instead of EQUAL TO, so for example if your character's prefab is somename, you can do this: AddPrefabPostInit("somename", function(inst) if not TheWorld.ismastersim then -- This has to be GLOBAL.TheWorld.ismastersim ONLY IF you haven't defined TheWorld as global via any means. return end -- If a player plays your modded character, and their (Steam user)name is NOT "allowedname", then this code will run. -- If they're named "allowedname", then nothing happens. if inst.name ~= "allowedname" then --do something end end) Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1832452 Share on other sites More sharing options...
Nicodesu Posted August 22, 2025 Share Posted August 22, 2025 (edited) 19 hours ago, Baguettes said: You can use ~= instead of == to make the statement be a NOT statement instead of EQUAL TO, so for example if your character's prefab is somename, you can do this: AddPrefabPostInit("somename", function(inst) if not TheWorld.ismastersim then -- This has to be GLOBAL.TheWorld.ismastersim ONLY IF you haven't defined TheWorld as global via any means. return end -- If a player plays your modded character, and their (Steam user)name is NOT "allowedname", then this code will run. -- If they're named "allowedname", then nothing happens. if inst.name ~= "allowedname" then --do something end end) Ah, oki, appreciate the help, will give it a try... and, where me put this? modmain, me presume? (´・ω・`) EDIT - Got a bit confuse with the steam user name, has it need to be the name when using to login or the name that shows on the steam page? Since the script gave effect either wrong name or correct name. or if there a way to detect KU_xxxxx in game instead to lessen the confusion? Edited August 22, 2025 by Nicodesu Added something again? Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1832504 Share on other sites More sharing options...
Baguettes Posted August 22, 2025 Share Posted August 22, 2025 8 hours ago, Nicodesu said: Ah, oki, appreciate the help, will give it a try... and, where me put this? modmain, me presume? (´・ω・`) EDIT - Got a bit confuse with the steam user name, has it need to be the name when using to login or the name that shows on the steam page? Since the script gave effect either wrong name or correct name. or if there a way to detect KU_xxxxx in game instead to lessen the confusion? inst.name is the name shown in-game, if you want the KUID you can use inst.userid instead. userid usually holds KUID. Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1832525 Share on other sites More sharing options...
Nicodesu Posted August 22, 2025 Share Posted August 22, 2025 1 minute ago, Baguettes said: inst.name is the name shown in-game, if you want the KUID you can use inst.userid instead. userid usually holds KUID. Oki, will give it another go, thx again (´ - ω -`) Link to comment https://forums.kleientertainment.com/forums/topic/104448-player-name-check/#findComment-1832526 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now