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 Sound Err?

Asked by
lytew 99
4 years ago

an error is happening in my sound variable .. the error is Players.lytew.PlayerScripts.dontsave_test: 13: attempt to index a nil value script:

local debounce1 = false
local work = game:GetService("Workspace")
local hitbox = work.all_lavas.hit_box
hitbox.Touched:connect(function(hit)
wait(1.5)
if debounce1 == false then
print('debounce false')
debounce1 = true
local gui = script.Parent.Parent.PlayerGui
local texto = 'Dont save Creyson'
local player = game:GetService("Players")
local soundclick = 'rbxassetid://1238528678'
local sound = player:GetPlayerFromCharacter(hit.Parent).PlayerGui.Soundclick

local findplayer = player:GetPlayerFromCharacter(hit.Parent)

if findplayer and findplayer.Character and findplayer.Character:FindFirstChild('Humanoid') then

local textscreen = script.localtext_dontsave:Clone()
textscreen.Parent = player:GetPlayerFromCharacter(hit.Parent).PlayerGui

print(findplayer.Name)
for i = 1,#texto do
wait(0.09)

player:GetPlayerFromCharacter(hit.Parent).PlayerGui.localtext_dontsave.TextLabel.Text = string.sub(texto,1,i)
sound:Play()
sound.Volume = 1




if player:GetPlayerFromCharacter(hit.Parent).PlayerGui.localtext_dontsave.TextLabel.Text == 'não salve creyson' then
    wait(1)
    player:GetPlayerFromCharacter(hit.Parent).PlayerGui.localtext_dontsave.TextLabel.Text = 'não salve creyson :('

    sound:Play()
    sound.Volume = 1

    wait(8)
    player:GetPlayerFromCharacter(hit.Parent).PlayerGui.localtext_dontsave:Destroy()

    wait(2)
    debounce1 = false
end
end
end 
end
end)

error is happening in Line 13

1 answer

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

You stated in line 11 that Player was a service. Later you are trying to (In line 13) get the player from the character. You're trying to get the player from the service. You should do -

local Player = game.Players.LocalPlayer

Hope that helps!

0
what is the difference between service and Get? lytew 99 — 4y
0
You can't compare them. What I am saying is that you said that the Player variable was a service. GetPlayerFromCharacter can only be performed on a character model. It's like trying to get the player from the workspace, if you understand. Which would be implying that you think that workspace is a player. Arj783 72 — 4y
Ad

Answer this question