'Attempt to index nil with number' database?

i have a database that works fine, but there is a problem in line 11-12, i am using a remote event to fetch intval in playergui, it is a local remote event, here is the code for the database script and remote event script:

--database
local remote = game.ReplicatedStorage.Shop
local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetDataStore("Info")


local function saveData(player) -- The functions that saves data

	local tableToSave = {
		player.leaderstats.Gold.Value; -- First value from the table
		player.leaderstats.WalkSpeed.Value; -- Second value from the table
		remote.FetchPriceAndMax:FireClient(player)[1];
		remote.FetchPriceAndMax:FireClient(player)[2]
	}

	local success, err = pcall(function()
		Data:SetAsync(player.UserId, tableToSave) -- Save the data with the player UserId, and the table we wanna save
	end)

	if success then -- If the data has been saved
		print("Data has been saved!")
	else -- Else if the save failed
		print("Data hasn't been saved!")
		warn(err)		
	end
end

game.Players.PlayerAdded:Connect(function(p)	
		-- Currency

		local Leaderstats = Instance.new("Folder", p)
		Leaderstats.Name = "leaderstats"

		local gold = Instance.new("IntValue", Leaderstats)
		local walkspeed = Instance.new("IntValue", Leaderstats)
		gold.Name = "Gold"
		walkspeed.Name = "WalkSpeed"
		-- DataBase

		local data
		local success, err = pcall(function()
			data = Data:GetAsync(p.UserId)
		end)

		if success then
		gold.Value = data[1]
		walkspeed.Value = data[2]
		remote.ChangePriceAndMax:FireClient(p, data[3], data[4])
		else
			print("Couldn't load!")
			warn(err)
		end

	p.CharacterAdded:Connect(function()
		p.Character.Humanoid.WalkSpeed = walkspeed.Value+16
			p.Character.Humanoid.Died:Connect(function()
			p.Team = game.Teams.spectator
		end)
		
			walkspeed.Changed:Connect(function()
				print("Changed!!")
			p.Character.Humanoid.WalkSpeed = walkspeed.Value+16
	end)
end)


game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves
	local success, err  = pcall(function()
		saveData(player) -- Save the data
	end)

	if success then
		print("Data has been saved")
	else
		print("Data has not been saved!")
		warn(err)
	end
end)

game:BindToClose(function() -- When the server shuts down
	for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players
		local success, err  = pcall(function()
				saveData(player) -- Save the data
		end)

		if success then
			print("Data has been saved")
		else
			print("Data has not been saved!")
			warn(err)
		end
	end
end)
end)
--event
local remote = game.ReplicatedStorage.Shop.FetchPriceAndMax

remote.OnClientEvent:Connect(function(p)
	local pl = p.PlayerGui.ScreenGui.shop.Speed
	return {pl.max.Value, pl.speedprice.Value}
end)

So where is the remote event located in? Remote events should be located in replicated storage

the local script is in playerscripts, and the remote event is in replicated storage, in a folder named ‘shop’

Put the local script(the script where your calling the remote event;on client event) in starter gui

ill try it right now
30 ch ars

nope, it still doesn’t work for some reason.

Mhmm, why not trying using remote functions?

good idea, i’ll try to use remote functions

Putting it there doesn’t change anything, it’ll still run and function the same way.

i get: attempt to index nil with ‘PlayerGui’

local remote = game.ReplicatedStorage.Shop:WaitForChild("FetchMaxAndPrice")
local shop = game.ReplicatedStorage.Shop
function remote.OnClientInvoke(player)
	local p = player.PlayerGui:WaitForChild("ScreenGui").Speed
	return {p.max.Value, p.speedprice.Value}
end

That’s not how you invoke and a remote function…

it’s my first time using remote functions, so idk what i’m really doing.

local remote = game.ReplicatedStorage.Shop:WaitForChild("FetchMaxAndPrice")
local shop = game.ReplicatedStorage.Shop
function remote.OnServerEvent(player)
	local p = player.PlayerGui:WaitForChild("ScreenGui").Speed
	return {p.max.Value, p.speedprice.Value}
end

Try this

that is not the problem, the problem is that i get 'attempt to index nil with ‘PlayerGui’

This is the problem, first off, you’re firing a remote event twice which is unnecessary, but the real problem is that remote events cannot return a value

well is there a way to make it return or am i just stuck with it?

Read the docs…

i tried using remote functions, but i got attempt to index nil with ‘PlayerGui’

I’d have to know how you set the remote up to help you with that. But you shouldn’t be getting values for anything from client → server. This just allows exploiters to set any value they want. You should send important values like this from server → client. But I dont understand why you’re using remote for this anyways. PlayerGui changes from server → client auto replicate.

i’m not an advanced dev or anything, so i just use what i know, and second, what do you mean by ‘set up’? i just made an event in a folder in replicated storage then made a localscript named fetch in playerscripts and made that code, and the database script, fetches the info, then loads, then when it exits, it saves.