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:
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
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.
@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]
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
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)