So i has a problem with a script Output says:
Players.SrOgurman.PlayerGui.Dialog.LocalScript:5: attempt to index local 'Player' (a nil value)
Here is the script itself:
local box = workspace.DialogTrigger
box.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local DialogScreen = Player.PlayerGui.Dialog
DialogScreen.Enabled = true
local TextHolder = DialogScreen.DialogText.Text
local text = "Test text"
if hit.Parent.Name ~= "*Here is the name of NPC*" then
for i = 1, #text do
TextHolder = string.sub(text,1,i)
local octave = 1
local Pitch = math.random(1,3)
if Pitch == 1 then
octave = math.random(0.8,0.89)
elseif Pitch == 2 then
octave = math.random(0.9,0.99)
elseif Pitch == 3 then
octave = math.random(1,1.5)
end
DialogScreen.Sound.PitchShiftSoundEffect.Octave = octave
script.Parent.Sound:Play()
end
end
end)
Output shows that mistake is made here:
local DialogScreen = Player.PlayerGui.Dialog
Any ideas how do i fix this code? Forgot to mention the most important. The Gui pops up but text that should've changed, doesnt for some reason even though the sound plays.

1 comment
nvm i found a solution myslef