How to get a player's physical body in a localscript?

usedSounds is an array from my serverscript, which is being passed over. I know this is functional bc I can print (usedSounds[1]) and it will print the variable I have inserted in the other script. The array is below:

local usedSounds = {
		RunningSoundId,
		DiedSoundId,
		ClimbingSoundId,
		FreeFallingSoundId,
		GettingUpSoundId,
		JumpingSoundId,
		LandingSoundId,
		SplashSoundId,
		SwimmingSoundId
	}

The variables in the array are listed above, with the first one changed.
the variables are:

local Running = 5721510093
	local Died = 0
	local Climbing = 0
	local FreeFalling = 0
	local GettingUp = 0
	local Jumping = 0
	local Landing = 0
	local Splash = 0
	local Swimming = 0
1 Like

I don’t quite understand what you mean by

but every sound iD inserted is supposed to be a number if I am understanding you correctly.

All of them except for the first are zero

1 Like

I don’t think “0” is a valid ID.

You only have a running animation, just use that?

1 Like

The problem isn’t that they all need IDs. It doesn’t even get to the rest of the numbers in the localscript bc of the error. Also, 0 would be fine, but nil would not work. 0 just doesn’t change the number, I programmed it that way:

for x=1, table.getn(setVariables), 1 do 
		if setVariables[x] ~= 0 then
			usedSounds[x]=setVariables[x]
			print("Sound Number " .. x .. " Was Changed by Script to Sound Id " .. usedSounds[x])
		else
			print("Sound Number " .. x .. " Will Stay as Default Sound")
			print(setVariables[x])
		end
	end

The running is the only one I am testing, it doesn’t get any further. I’ll try the others when the first one works.

1 Like

Alright well thanks for trying let me see if I can figure it out myself based on the errors now.

change the

part to:

local character = workspace:WaitForChild(player.Name)
1 Like

I already told him how to find that.
And it’s

Player.Character

I guess yours could work, too.

1 Like

Sorry I was writing a reply before reading all the replys

1 Like

@Gusshiy @Aeventy
Here’s the one error that’s popping up now:
HumanoidRootPart is not a valid member of Model "Workspace.Derpee_Kirbee"
Here’s the script:

local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()

local function changeSounds (usedSounds)
	print("Remote Event Fired. Setting IDs...")
	print(usedSounds[1])
	print(player.Name)
	print(character.Name)
	print(usedSounds[1])
	character.HumanoidRootPart.Running.SoundId="rbxassetid://" .. usedSounds[1]
	print("Running Sound Changed to " .. usedSounds[1])
	character.HumanoidRootPart.Died.SoundId="rbxassetid://" .. usedSounds[2]
	character.HumanoidRootPart.Climbing.SoundId="rbxassetid://" .. usedSounds[3]
	character.HumanoidRootPart.FreeFalling.SoundId="rbxassetid://" .. usedSounds[4]
	character.HumanoidRootPart.GettingUp.SoundId="rbxassetid://" .. usedSounds[5]
	character.HumanoidRootPart.Jumping.SoundId="rbxassetid://" .. usedSounds[6]
	character.HumanoidRootPart.Landing.SoundId="rbxassetid://" .. usedSounds[7]
	character.HumanoidRootPart.Splash.SoundId="rbxassetid://" .. usedSounds[8]
	character.HumanoidRootPart.Swimming.SoundId="rbxassetid://" .. usedSounds[9]
end
remoteEvent.OnClientEvent:Connect(changeSounds)

So the error is appearing on line 12, or
character.HumanoidRootPart.Running.SoundId="rbxassetid://" .. usedSounds[1]

1 Like

When is the RemoteEvent Firing?

1 Like

@Gusshiy at the end of a server script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
--[[
The SoundIds that can be assigned. When changing, use example:
local example = "rbxassetid://5721510093"
When adding your own sounds, add "id" to the end of "rbxasset"

--]]

Players.PlayerAdded:Connect(function(player)
	
	--These are the variables you change
	local Running = 5721510093
	local Died = 0
	local Climbing = 0
	local FreeFalling = 0
	local GettingUp = 0
	local Jumping = 0
	local Landing = 0
	local Splash = 0
	local Swimming = 0
	
	local RunningSoundId = "rbxasset://sounds/action_footsteps_plastic.mp3"
	local DiedSoundId = "rbxasset://sounds/uuhhh.mp3"
	local ClimbingSoundId = "rbxasset://sounds/action_footsteps_plastic.mp3"
	local FreeFallingSoundId = "rbxasset://sounds/action_falling.mp3"
	local GettingUpSoundId = "rbxasset://sounds/action_get_up.mp3"
	local JumpingSoundId = "rbxasset://sounds/action_jump.mp3"
	local LandingSoundId = "rbxasset://sounds/action_jump_land.mp3"
	local SplashSoundId = "rbxasset://sounds/impact_water.mp3"
	local SwimmingSoundId = "rbxasset://sounds/action_swim.mp3"
	
	
	
	local setVariables = {
		Running,
		Died,
		Climbing,
		FreeFalling,
		GettingUp,
		Jumping,
		Landing,
		Splash,
		Swimming
	}
	
	local usedSounds = {
		RunningSoundId,
		DiedSoundId,
		ClimbingSoundId,
		FreeFallingSoundId,
		GettingUpSoundId,
		JumpingSoundId,
		LandingSoundId,
		SplashSoundId,
		SwimmingSoundId
	}
	
	print("Running sound is " .. setVariables[1])
	print(table.getn(setVariables))
	for x=1, table.getn(setVariables), 1 do 
		if setVariables[x] ~= 0 then
			usedSounds[x]=setVariables[x]
			print("Sound Number " .. x .. " Was Changed by Script to Sound Id " .. usedSounds[x])
		else
			print("Sound Number " .. x .. " Will Stay as Default Sound")
			print(setVariables[x])
		end
	end

	remoteEvent:FireClient(player, usedSounds)
	
end)

You might want to put in a workspace:WaitForChild(player.Name) at the start of the PlayerAdded event. It may be firing before the HumanoidRootPart is loaded

@Gusshiy you mean the PlayerAdded in the ServerScript?

@Derpee_Kirbee yes. Sorry I wasn’t clear enough

@Gusshiy but there’s no “player” defined in the server script

@Derpee_Kirbee it is. At the PlayerAdded Function, it is defined right here V
Players.PlayerAdded:Connect(function( -->Defined Right Here--> player))

Check this out

this may work

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local soundNames = {
    "Running",
    "Died",
    "Climbing",
    "FreeFalling",
    "GettingUp",
    "Jumping",
    "Landing",
    "Splash",
    "Swimming"
}

local function changeSounds (usedSounds)
	print("Remote Event Fired. Setting IDs...")
	print(usedSounds[1])
	print(player.Name)
	print(character.Name)
    print(usedSounds[1])
    

    for i = 1, #soundNames do
        if type(usedSounds[i]) == "number" and usedSounds[i] ~= 0 then
            humanoidRootPart:WaitForChild(soundNames[i]).SoundId = "rbxassetid://" .. tostring(usedSounds[i])
        end
    end
end
remoteEvent.OnClientEvent:Connect(changeSounds)

to be sure, you can add a wait(5) before firing the remote event in your server script

	wait(5)
	remoteEvent:FireClient(player, usedSounds)

Why else, your server script will run before your client script runs

I don’t know if this helps

I changed the player’s death sound in my game

The LocalScript you used in StarterPlayer is placed in StarterPlayerScripts

I did not try to change the voice inside the character

If this succeeds, you should make a change operation every time the player dies