"attempt to index nil with 'Play' " and "attempt to index nil with 'MainGui' "

So, im making a game like PLS DONATE, but i am having an issue, first off, my remote event “Server —> Client” for playing audio on the client using an server-sided script, doesn’t work, and shows "attempt to index nil with ‘Play’, however, the audio exists before i even claim a booth!

There is another issue, with MainGui being nil in PlayerGui, and it still exists before i even claim a booth, i use that to display error messages on the client.

Scripts:

Server-sided Script:

script.Parent.ClaimBooth.Triggered:Connect(function(player)
	local remotes = game.ReplicatedStorage.Remotes
	print(player.Values.HasStand.Value)
	if player.Values.HasStand.Value == false then
		local audioClaim = game.ReplicatedStorage.Audios.ClaimBooth
		remotes.audioRemote:FireClient(player, audioClaim)
		script.Parent.Owner.Value = player.UserId
		player.Values.HasStand.Value = true
		script.Parent.ClaimBooth.Enabled = false
	else
		local errormsg = player.PlayerGui.MainGui.Error
		local audioError = game.ReplicatedStorage.Audios.Error
		remotes.audioRemote:FireClient(player, audioError)
		remotes.errorRemote:FireClient(player, "You cannot claim a booth when you already claimed one!")
	end
end)

LocalScript for “Server —> Client” remotes

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local errorEvent = ReplicatedStorage.Remotes:WaitForChild("errorRemote")
local audioEvent = ReplicatedStorage.Remotes:WaitForChild("audioRemote")

local function errortext(player, text)
	local errormsg = player.PlayerGui.MainGui.Error
	errormsg.Text = text
	errormsg.Visible = true
	wait(5)
	errormsg.Visible = false
end

errorEvent.OnClientEvent:Connect(errortext)

local function playAudio(player, audio)
	audio:Play()
end

audioEvent.OnClientEvent:Connect(playAudio)

Hope yall can help me!

can someone help me? please? no one is responding

I noticed in both functions that you are using the parameters player and a one other parameter. The first parameter of a :FireClient() is ALWAYS the player argument, and is not passed to the client - it merely tells the backend of the server-side who to send the information to.

If you remove the player parameter in both client-side scripts, it should resolve your issue


if my explanation made no sense, just replace your client code with this

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local errorEvent = ReplicatedStorage.Remotes:WaitForChild("errorRemote")
local audioEvent = ReplicatedStorage.Remotes:WaitForChild("audioRemote")

local function errortext(text)
	local errormsg = player.PlayerGui.MainGui.Error
	errormsg.Text = text
	errormsg.Visible = true
	wait(5)
	errormsg.Visible = false
end

errorEvent.OnClientEvent:Connect(errortext)

local function playAudio(audio)
	audio:Play()
end

audioEvent.OnClientEvent:Connect(playAudio)
1 Like

i need the player argument for errortext, or else it shows this


image

then define the player at the start of the script

local player = game.Players.LocalPlayer
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.