Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index a nil value?

So hey guys. I have been trying to make a script for void script builder and i tried this script here, But it just says "Attempt to index a nil value" and idk what to do. So if you could help me that will be great.

local msg = "bruh"
local sound = Instace.new("Sound", torso)
 
if game.Player:Chat (msg) then
sound.Volume = 12
sound.SoundId = "rbxassetid://3154962208"
sound.Play()
end

1 answer

There's quite a few things wrong with this, so I'll list them as bullet points.

*"Instance" has been misspelled as "Instace"

*torso hasn't been defined, at least in the code you've given

*"Player" is not a valid property of game, but Players is

*Even if you were actually referencing a player correctly, "Chat" is not a valid method

*A sounds volume can only be set to a maximum of 10

*Play is a method of Sound, it's not meant to be called as a function

Correcting as many issues as I could, the code looks like this

--LocalScript
local msg = "bruh"
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local sound = nil
player.CharacterAdded:Connect(function(character)
	wait()
	sound = Instance.new("Sound", character:FindFirstChild("Torso") or character.UpperTorso)
end)

player.Chatted:Connect(function(msg)
	sound.SoundId = "rbxassetid://3154962208"
	sound:Play()
end)

1 comment

0

thx lol

This discussion is preserved as it was. New answers, comments, and votes are closed.