I made this script for a tool with a sound and particle emitter in the tool
when ever i activate the tool, i get the error "Sound is not a valid member of tool" is there anything wrong with the script? (The error sends me to line 3 by the way)
Edit: The solution was to add ":WaitForChild()" as the sound didn't load in time.
local tool = script.Parent
local character = tool.Parent
local sound = tool.Sound
local debounce = false
local on = false
local aura = tool.ParticleEmitter
tool.Activated:Connect(function()
if debounce == false then
debounce = true
if on == false then
on = true
local soundclone = sound:Clone()
local auraclone = aura:Clone()
soundclone.Name = "Kaioken"
auraclone.Name = "Kaioken"
soundclone.Parent = character.Torso
auraclone.Parent = character.Torso
soundclone:Play()
debounce = false
else
local children = character.Torso:GetChildren()
for i = 1, #children do
print(i, children[i].Name)
end
end
end
end)

1 comment
either the issue is what sonysunny said, or your sound actually isnt loaded by the time the script runs. try using :WaitForChild()