Remote events; Sending accessory through remote events

I want my remote event to send the player and a string to the server script.

In my server script, it is reading the accessory as a Player for some reason. It’s giving me this output when I try to print the accessory value: "Value is not a valid member of Player “Players.ballerawesomeg_dog” ".5

Local Script:

local gPlayers = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local marketPlace = game:GetService("MarketplaceService")
--    ^ Services ^

local Player = gPlayers.LocalPlayer
local event1 = repStorage.LockerFolder.ChangeLocker
local accessory = serverStorage:WaitForChild("FastHelmet").CustomFastHelmet
script.Parent.MouseButton1Click:Connect(function()
	if marketPlace:UserOwnsGamePassAsync(Player.UserId, 36177941) then
		print("Player Owns")
		event1:FireServer(Player, accessory)
	else
		print("Player Doesn't Own")
		marketPlace:PromptGamePassPurchase(Player)
	end
end)


Server Script:

local gPlayers = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local marketPlace = game:GetService("MarketplaceService")
--    ^ Services ^

local event1 = repStorage.LockerFolder.ChangeLocker

event1.OnServerEvent:Connect(function(Player, accessory)
	local char = Player.Character
	local Hum = char.Humanoid
	local accessoryLoaded = accessory:Clone()
	print(accessory.Name)
	Hum:AddAccessory(accessoryLoaded)
end)

Replace this line

print("Player Owns")
event1:FireServer(Player, accessory)

with

print("Player Owns")
event1:FireServer(accessory)

The player value is automatically passed through, so you sent it twice

That error is basically saying that you’re trying to INDEX a player with a value. If you meant to reference an actual value, you should check that.

I think this is right, although I just ran some tests and for some reason the script isn’t even registering the MouseButton1Click: (Didn’t print the “Pass Click”)

script.Parent.MouseButton1Click:Connect(function()
	print("Pass Click")
	if marketPlace:UserOwnsGamePassAsync(Player.UserId, 36177941) then
		print("Player Owns")
		event1:FireServer(accessory)
	else
		print("Player Doesn't Own")
		marketPlace:PromptGamePassPurchase(Player)
	end
end)

Shouldn’t have affected the mouseclick…

Might be the WaitForChild(“FastHelmet”) bit that is causing a delay

Hmm, switched it and it still isn’t registering the click. I’ll look for more errors towards the beginning of the script

Everything looks good to me, but I need to get off for the night, I’ll get back on tomorrow and see if there is any more possible solutions.

To my knowledge, I believe local scripts CANNOT access ServerStorage or ServerScriptService. You can put it in Replicated storage where both of it can access it.

This was part of the problem, but the other part was quite embarrassing, to say the least, turns out all the script I was typing was in the wrong ImageButton.

1 Like

Also, I found another issue. You’re sending the player and the accessory. Why? Player is always automatically the first argument when you’re receiving on the server. You don’t need to send it from the client. However for the client, you must send the player to the client.