Server/Client changing string from a players username to 'nil'

Hiya, I have an issue where when sending data from the client to the server using a remote event, the server changes the string from a string to ‘nil’ I have tried looking to see where the issue is however I cant find it.

CLient script to send the data to the server

        local PlayerName = script.Parent.PlrName.Text -- Gets player name
        print("Client Sending Order to Delete for "..PlayerName) -- Prints out name correctly
        game.ReplicatedStorage.IFE.DeleteOrder:FireServer(PlayerName) -- Sends data

Script on the server

game.ReplicatedStorage.IFE.DeleteOrder.OnServerEvent:Connect(function(Player, PlayerName)
    print("Server Sending Order to Delete for "..tostring(PlayerName))
    
    game.ReplicatedStorage.IFE.DeleteOrder:FireAllClients(tostring(PlayerName))
end)

The recieving client script

game.ReplicatedStorage.IFE.DeleteOrder.OnClientEvent:Connect(function(Player, PlayerName)
	print("Client Deleteing for "..tostring(PlayerName))
	local button = script.Parent.Orders:FindFirstChild(tostring(PlayerName))
	button:Destroy()
end)

The error I get is that the player name is printing as ‘nil’ on the recieving client script

1 Like

Can I see the output for both the server and client side print statement

Wait, I managed to get it working on the server side but when It goes to all clients it comes out as nil
image
let me change the first message

Could you show us what you’re trying to destroy on line 104? Sending the LocalScript would help

I am trying to destroy a button that was created earlier on. the script of it is here

	print("Player: "..Player.Name)
	print("Main Meal: "..MainMeal)
	print("Drink: "..Drink)
	print("Dessert: "..Dessert)
	print("Premium: "..tostring(Premium))

	local NewButton = script.Parent.PlayerName:Clone()
	NewButton.Parent = OrdersFrame

	NewButton.Visible = true
	NewButton.Text = Player.Name
	NewButton.Drink.Value = Drink
	NewButton.Dessert.Value = Dessert
	NewButton.MainMeal.Value = MainMeal
	if Premium == true then
		NewButton.Premium.Value = true
	else
		NewButton.Premium.Value = false
	end
	NewButton.MouseButton1Click:Connect(function(player)
		script.Parent.PlrName.Text = Player.Name
		local role = Player:GetRoleInGroup(7402874)
		script.Parent.Role.Text = role
		script.Parent.Main.Text = tostring(MainMeal)
		script.Parent.Drink.Text = Drink
		script.Parent.Premium.Text = tostring(Premium)
		if NewButton.Premium.Value == true then
			script.Parent.Dessert.Text = Dessert
		else
			script.Parent.Dessert.Text = "nil"
		end	
	end)

end)

This is inside of a .OnServerEvent function.

The button does not exist because you have an invalid parameter.
The OnClientEvent does not have a default player parameter. You can just put it as PlayerName.


Also, before destroying the button, I suggest that you’d check if it exists first.

Client Script
game.ReplicatedStorage.IFE.DeleteOrder.OnClientEvent:Connect(function(PlayerName)
	local button = script.Parent.Orders:FindFirstChild(tostring(PlayerName))
	if button then
		print("Client Deleteing for "..tostring(PlayerName))
		button:Destroy()
	end
end)