Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index a nil value?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
thx lol TubiGamingDK 4 — 4y
Ad

Answer this question