Okay so today I was starting my work on a script that is supposed to be user-friendly, where they can just insert sound IDs to replace the default sounds made from walking, jumping, etc. In a for loop, I was trying to find the number of items in an array, but eventually got the problem that the # function does not count nil items, making this only count for the first time. Can someone please explain how I would change this from the current “9” that is there, to be more accurate if deleting or adding more sounds?
THE ENTIRE SCRIPT:
local Players = game:GetService("Players")
--[[
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 = nil
local Climbing = nil
local FreeFalling = nil
local GettingUp = nil
local Jumping = nil
local Landing = nil
local Splash = nil
local Swimming = nil
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 defaultSounds = {
RunningSoundId,
DiedSoundId,
ClimbingSoundId,
FreeFallingSoundId,
GettingUpSoundId,
JumpingSoundId,
LandingSoundId,
SplashSoundId,
SwimmingSoundId
}
print(#setVariables)
for x=1, 9, 1 do
if setVariables[x] ~= nil then
setVariables[x]=defaultSounds[x]
print("Sound Number " .. x .. " Was Changed by Script to Sound Id " .. setVariables[x])
else
print("Sound Number " .. x .. " Will Stay as Default Sound")
print(setVariables[x])
end
end
wait(5)
local sounds = player.HumanoidRootPart
sounds.Running.SoundId=defaultSounds
sounds.Died.SoundId=DiedSoundId
sounds.Climbing.SoundId=ClimbingSoundId
sounds.FreeFalling.SoundId=FreeFallingSoundId
sounds.GettingUp.SoundId=GettingUpSoundId
sounds.Jumping.SoundId=JumpingSoundId
sounds.Landing.SoundId=LandingSoundId
sounds.Splash.SoundId=SplashSoundId
sounds.Swimming.SoundId=SwimmingSoundId
end)
THE PROBLEM AREA:
for x=1, 9, 1 do
Thanks for all the help in advance