Why does the server get a nil string?

So I am making a shop for my game where you can buy and equip skins, the issue is whenever I want to buy a skin, it doesn’t work. There isn’t any error in output and I think it may be a nil string but I didn’t make it nil? Any help would be appreciated!

Local script:

local player = game.Players.LocalPlayer
local coins = player:WaitForChild('Coins')
local buySound = script.Parent.Parent.Parent:WaitForChild('BuySound')
local click = script.Parent.Parent.Parent:WaitForChild('Click')
local events = game.ReplicatedStorage:WaitForChild('RemoteEvents')

script.Parent:WaitForChild('Button').MouseButton1Click:Connect(function()
	if coins.Value >= script.Parent.Price.Value and script.Parent.Owned.Value == false then
		events.BuyEvent:FireServer(player, 'SkinTest')
	elseif script.Parent.Owned.Value == true then
		events.EquipEvent:FireServer(player, 'SkinTest')
		script.Parent.Button.Text = 'Equipped'
	end
end)

events:WaitForChild('BuyEvent').OnClientEvent:Connect(function(name, successOrNo)
	if successOrNo == true and name == script.Parent.Name then
		buySound:Play()
		script.Parent.Button.Text = 'Equip'
		script.Parent.Status.TextColor3 = Color3.new(1, 1, 1)
		script.Parent.Status.Text = 'Owned'
	end
end)

Server script:

events.BuyEvent.OnServerEvent:Connect(function(player, name)
	local item = game.ServerStorage.SkinsCost:FindFirstChild(name)
	if item then
		if player:FindFirstChild('Coins').Value >= item.Value then
			player:FindFirstChild('Skins'):FindFirstChild(item.Name).Value = true
			events.BuyEvent:FireClient(player, name, true)
		end
	end
end)

events.EquipEvent.OnServerEvent:Connect(function(player, name)
	local item = player.Skins:FindFirstChild(name)
	if item.Value == true then
		player.EquippedSkin.Value = item.Name
	end
end)
1 Like

You dont need to pass player through the arguments of a local script.

script.Parent:WaitForChild('Button').MouseButton1Click:Connect(function()
	if coins.Value >= script.Parent.Price.Value and script.Parent.Owned.Value == false then
		events.BuyEvent:FireServer('SkinTest')
	elseif script.Parent.Owned.Value == true then
		events.EquipEvent:FireServer('SkinTest')
		script.Parent.Button.Text = 'Equipped'
	end
end)

The player argument determines who brought the skin

and the playeer argument is already there when an event is fired.

Ah I didn’t know, I thought it was for firing clients only

Wait no, this issue is your firing an event on the local script, then detecting that event on the same local script and the server script.

1 Like
events.BuyEvent:FireServer(player, 'SkinTest')
events.EquipEvent:FireServer(player, 'SkinTest')

These FireServer() calls are your issue, you don’t need to explicitly pass the local player belonging to the client which is firing the server as an argument, this is done automatically.

1 Like