Players: Create Humanoid Model From UserId() causing error when testing in studio

Currently working on some stuff which requires the spawning of a “decoy” model of the player upon their death, it seems to work, however, upon testing on a local server, the error “Invalid UserId” appears. I believe this might be caused as while testing with local server, UserIds are set as stuff such as -1, -2, and such. This might be the cause of the problem but I am unsure on wether it is, or if its just a problem with my script

for context, here is my script:

local function spawnPlayer(player)
	--Irrelevant stuff
	-- Proximity Prompt events
        -- prox is a proximity prompt, ik that it works as the player is still able to die when it is activated
	prox.Triggered:Connect(function()
		player.Character.Humanoid.Health = 0
		local inspectable = plrs:CreateHumanoidModelFromUserId(player.UserId)
		inspectable.Parent = workspace
	end)
        --Irrelevant stuff
end

remoteEvent.OnServerEvent:Connect(spawnPlayer)
1 Like

Yup, you are right, its because -1 its not a valid userID of an existant player in roblox.

If you need to run more tests in local server, you should change the approach of how you create the inspectable model.

What about, grabbing the HumanoidDescription when player joins, save it into a folder or table renaming it to the UserId, upon dead, use the userID find the proper HumanoidDescription, create a rig model and apply the HumanoidDescription to it, in that way, you are not getting the information from roblox, so it will work with userIds like -1, -2, etc

btw this should mean that it would all work in actual roblox right?

(although I should probably still change it)

1 Like

Yup, it works for normal roblox servers, and for the local server for testing. Its an approach I use in games when needing to get clones rigs from players

1 Like

Cant you just use Player:LoadCharacter()

no, that loads the player character, im making a seperate model

Then cant you just make Player.Character:Clone()

1 Like

idk

i mean this all happens AFTER the player dies

oh yea and theres stuff in player.character that would be annoying to get rid of

I remember there was a event for humanoid when its dead idk if its .Died or .Dead

its Humanoid.Died (but like, the humanoid is dead, so everything is more messy)

also i already spent like 10 hours on dis and im too lazy to change it since its just a minor thing

ig maybe ill do dat if i need to idk

Applying a HumanoidDescription to a Dummy, or cloning the character of the player when player joins and clone that model and place it in workspace, any of both fired by a Humanoid.Died event or any custom event that you are using in your game, both ways are easy to do.

I prefer to not try to clone or get information from the player, or roblox website, when a player Humanoid.Died event triggers. I prefer to have the data ready saved somewhere. And when Humanoid.Died event triggers, just find that data saved previously and create the clones, rigs etc.

For example a podium, where I wont place the real players, just rigged clones using the winner’s HumanoidDescriptions, or character clones previously saved.
Less computing stuff at that moment if everything already exist, and deleting it when player leaves

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.